ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-05-18 06:19:19
Exec Total Coverage
Lines: 2013 4564 44.1%
Functions: 142 337 42.1%
Branches: 1343 3758 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/replay_upload.h"
27 #include "zc/zc_init.h"
28 #include "init.h"
29 #include "zc/replay.h"
30 #include "zc/cheats.h"
31 #include "zc/render.h"
32 #include "base/zc_math.h"
33 #include "base/zapp.h"
34 #include "dialog/cheatkeys.h"
35 #include "metadata/metadata.h"
36 #include "zc/zelda.h"
37 #include "zc/saves.h"
38 #include "tiles.h"
39 #include "base/colors.h"
40 #include "pal.h"
41 #include "base/zsys.h"
42 #include "base/qst.h"
43 #include "zc/zc_sys.h"
44 #include "play_midi.h"
45 #include "gui/jwin_a5.h"
46 #include "base/jwinfsel.h"
47 #include "base/gui.h"
48 #include "midi.h"
49 #include "subscr.h"
50 #include "zc/maps.h"
51 #include "sprite.h"
52 #include "zc/guys.h"
53 #include "zc/hero.h"
54 #include "zc/title.h"
55 #include "particles.h"
56 #include "sound/zcmusic.h"
57 #include "zconsole.h"
58 #include "zc/ffscript.h"
59 #include "dialog/info.h"
60 #include "dialog/alert.h"
61 #include "zc/combos.h"
62 #include "zc/jit.h"
63 #include "zc/zc_subscr.h"
64 #include <fmt/format.h>
65 #include "zconsole/ConsoleLogger.h"
66 #include "zinfo.h"
67 #include "base/misctypes.h"
68 #include "music_playback.h"
69 #include "base/new_menu.h"
70 #include "base/files.h"
71 #include "iter.h"
72
73 #ifdef __EMSCRIPTEN__
74 #include "base/emscripten_utils.h"
75 #endif
76
77 using namespace std::chrono_literals;
78
79 extern bool Playing;
80 int32_t sfx_voice[WAV_COUNT];
81 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
82 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
83
84 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
85 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
86
87 extern byte monochrome_console;
88
89 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
90 extern int32_t loadlast;
91 extern char *sfx_string[WAV_COUNT];
92 byte use_dwm_flush;
93 byte use_save_indicator;
94 int32_t paused_midi_pos = 0;
95 byte midi_suspended = 0;
96 byte zc_192b163_warp_compatibility;
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 #ifdef ALLEGRO_LINUX
111 static const char *samplepath = "samplesoundset/patches.dat";
112 #endif
113 char qst_files_path[2048];
114
115 extern TopMenu the_player_menu;
116 #ifdef _MSC_VER
117 #define getcwd _getcwd
118 #endif
119
120 bool rF11();
121 bool rI();
122 bool rQ();
123 bool zc_key_pressed();
124
125 #ifdef _WIN32
126
127 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
128 extern "C"
129 {
130 typedef HRESULT(WINAPI *t_DwmFlush)();
131 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
132 }
133
134 void do_DwmFlush()
135 {
136 static HMODULE shell = LoadLibrary("dwmapi.dll");
137
138 if(!shell)
139 return;
140
141 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
142 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
143
144 BOOL enabled;
145 isEnabled(&enabled);
146
147 if(isEnabled)
148 flush();
149 }
150
151 #endif // _WIN32
152
153 304 void zc_exit(int code)
154 {
155 extern CConsoleLoggerEx zscript_coloured_console;
156
157 304 set_is_exiting();
158
159
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if (replay_get_mode() == ReplayMode::Record) replay_save();
160 304 replay_stop();
161 304 music_stop();
162 304 kill_sfx();
163
164
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 297 times.
304 if (get_qr(qr_OLD_SCRIPT_VOLUME))
165 {
166 //restore user volume settings
167
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 1 times.
297 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
168 {
169 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
170 1 }
171
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 1 times.
297 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
172 {
173 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
174 1 }
175
2/2
✓ Branch 0 taken 296 times.
✓ Branch 1 taken 1 times.
297 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
176 {
177 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
178 1 }
179
1/2
✓ Branch 0 taken 297 times.
✗ Branch 1 not taken.
297 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
180 {
181 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
182 }
183 297 }
184
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
185 {
186 pan_style = (int32_t)FFCore.usr_panstyle;
187 }
188 304 save_game_configs();
189
190 304 zscript_coloured_console.kill();
191 304 jit_shutdown();
192 304 quit_game();
193
194 304 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
195 304 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
196
197 304 allegro_exit();
198 304 exit(code);
199 }
200
201 92877 bool flash_reduction_enabled(bool check_qr)
202 {
203
4/4
✓ Branch 0 taken 88452 times.
✓ Branch 1 taken 4425 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92049 times.
92877 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
204 }
205
206 // Dialogue largening
207 void large_dialog(DIALOG *d)
208 {
209 large_dialog(d, 1.5);
210 }
211
212 void large_dialog(DIALOG *d, float RESIZE_AMT)
213 {
214 if(!d[0].d1)
215 {
216 d[0].d1 = 1;
217 int32_t oldwidth = d[0].w;
218 int32_t oldheight = d[0].h;
219 int32_t oldx = d[0].x;
220 int32_t oldy = d[0].y;
221 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
222 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
223 d[0].w = int32_t(d[0].w*RESIZE_AMT);
224 d[0].h = int32_t(d[0].h*RESIZE_AMT);
225
226 for(int32_t i=1; d[i].proc !=NULL; i++)
227 {
228 // Place elements horizontally
229 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
230 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
231
232 if(d[i].proc != d_stringloader)
233 {
234 if(d[i].proc==d_bitmap_proc)
235 {
236 d[i].w *= 2;
237 }
238 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
239 }
240
241 // Place elements vertically
242 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
243 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
244
245 // Vertically resize elements
246 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
247 {
248 d[i].h = int32_t((double)d[i].h*1.5);
249 }
250 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
251 {
252 d[i].y += int32_t((double)d[i].h*0.25);
253 d[i].h = int32_t((double)d[i].h*1.25);
254 }
255 else if(d[i].proc==d_bitmap_proc)
256 {
257 d[i].h *= 2;
258 }
259 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
260
261 // Fix frames
262 if(d[i].proc == jwin_frame_proc)
263 {
264 d[i].x++;
265 d[i].y++;
266 d[i].w-=4;
267 d[i].h-=4;
268 }
269 }
270 }
271
272 for(int32_t i=1; d[i].proc!=NULL; i++)
273 {
274 if(d[i].proc==jwin_slider_proc)
275 continue;
276
277 // Bigger font
278 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
279
280 if(!d[i].dp2 && bigfontproc)
281 {
282 d[i].dp2 = get_zc_font(font_lfont_l);
283 }
284 else if(!bigfontproc)
285 {
286 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
287 }
288
289 // Make checkboxes work
290 if(d[i].proc == jwin_check_proc)
291 d[i].proc = jwin_checkfont_proc;
292 else if(d[i].proc == jwin_radio_proc)
293 d[i].proc = jwin_radiofont_proc;
294 }
295
296 jwin_center_dialog(d);
297 }
298
299 static char cfg_sect[] = "zeldadx"; //We need to rename this.
300 static char ctrl_sect[] = "Controls";
301 static char sfx_sect[] = "Volume";
302
303 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
304 {
305 return D_O_K;
306 }
307
308 bool is_reserved_key(int c)
309 {
310 switch(c)
311 {
312 case KEY_ESC:
313 return true;
314 }
315 return false;
316 }
317 bool is_reserved_keycombo(int c, int modflag)
318 {
319 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
320 return true;
321 return false;
322 }
323 bool checkcheat(Cheat cheat)
324 {
325 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
326 return true; //Main key pressed
327 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
328 return true; //Alt key pressed
329 return false;
330 }
331 304 void load_default_cheatkeys()
332 {
333 304 memset(cheatkeys, 0, sizeof(cheatkeys));
334 304 cheatkeys[Cheat::Life][0] = KEY_H;
335 304 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
336 304 cheatkeys[Cheat::Magic][0] = KEY_M;
337 304 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
338 304 cheatkeys[Cheat::Rupies][0] = KEY_R;
339 304 cheatkeys[Cheat::Bombs][0] = KEY_B;
340 304 cheatkeys[Cheat::Arrows][0] = KEY_A;
341 304 cheatkeys[Cheat::Clock][0] = KEY_I;
342 304 cheatkeys[Cheat::Walls][0] = KEY_F11;
343 304 cheatkeys[Cheat::Fast][0] = KEY_Q;
344 304 cheatkeys[Cheat::Light][0] = KEY_L;
345 304 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
346 304 cheatkeys[Cheat::Kill][0] = KEY_K;
347 304 cheatkeys[Cheat::GoTo][0] = KEY_G;
348 304 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
349 304 cheatkeys[Cheat::ShowL0][0] = KEY_0;
350 304 cheatkeys[Cheat::ShowL1][0] = KEY_1;
351 304 cheatkeys[Cheat::ShowL2][0] = KEY_2;
352 304 cheatkeys[Cheat::ShowL3][0] = KEY_3;
353 304 cheatkeys[Cheat::ShowL4][0] = KEY_4;
354 304 cheatkeys[Cheat::ShowL5][0] = KEY_5;
355 304 cheatkeys[Cheat::ShowL6][0] = KEY_6;
356 304 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
357 304 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
358 304 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
359 304 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
360 304 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
361 304 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
362 304 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
363 304 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
364 304 }
365
366 static bool loaded_game_configs;
367
368 304 void load_game_configs()
369 {
370 304 loaded_game_configs = true;
371 304 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
372 304 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
373 304 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
374 304 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
375 304 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
376 304 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
377 304 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
378 304 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
379 304 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
380 304 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
381 304 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
382 304 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
383 304 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
384 304 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
385
386 //cheat modifier keya
387 304 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
388 304 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
389 304 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
390 304 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
391
392 //cheat keys
393 304 load_default_cheatkeys();
394 char buf[256];
395
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 10944 times.
11248 for(size_t q = 1; q < Cheat::Last; ++q)
396 {
397
1/2
✓ Branch 0 taken 10944 times.
✗ Branch 1 not taken.
10944 if(!bindable_cheat((Cheat)q)) continue;
398 10944 std::string cheatname = cheat_to_string((Cheat)q);
399
1/2
✓ Branch 0 taken 10944 times.
✗ Branch 1 not taken.
10944 util::lowerstr(cheatname);
400 10944 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
401
1/2
✓ Branch 0 taken 10944 times.
✗ Branch 1 not taken.
10944 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
402 10944 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
403
1/2
✓ Branch 0 taken 10944 times.
✗ Branch 1 not taken.
10944 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
404 10944 }
405
406
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
407 joystick_index = 0;
408
409 304 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
410 304 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
411 304 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
412 304 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
413 304 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
414 304 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
415 304 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
416 304 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
417 304 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
418 304 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
419
420 304 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
421 304 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
422 304 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
423 304 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
424
425 304 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
426 304 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
427 304 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
428 304 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
429 304 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
430 304 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
431 304 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
432 304 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
433 304 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
434 304 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
435 304 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
436
437 304 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
438 304 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
439 304 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
440 304 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
441
442 304 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
443
444 304 midi_volume = zc_get_config(sfx_sect,"midi",255);
445 304 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
446 304 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
447 304 pan_style = zc_get_config(sfx_sect,"pan",1);
448 304 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
449 304 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
450 304 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
451 304 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
452 304 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
453 304 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
454 304 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
455 304 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
456 304 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
457 #ifdef __EMSCRIPTEN__
458 if (em_is_mobile()) NameEntryMode = 2;
459 #endif
460 304 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
461 304 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
462 304 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
463 304 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
464 304 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
465 304 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
466
467 304 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
468 304 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
469 304 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
470 304 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
471 304 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
472 304 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
473 304 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
474
475 304 loadlast = zc_get_config(cfg_sect,"load_last",0);
476
477 304 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
478
479 304 info_opacity = zc_get_config("zc","debug_info_opacity",255);
480 #ifdef _WIN32
481 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
482 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
483 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
484
485 // This one's for Aero
486 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
487
488 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
489 #else //UNIX
490 304 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
491 304 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
492 #endif
493 304 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
494 304 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
495
496 304 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
497 304 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
498 304 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
499 304 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
500 304 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
501 304 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
502 304 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
503 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
504 304 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
505 304 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
506 304 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
507 304 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
508 304 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
509 304 }
510
511 void save_control_configs(bool kb)
512 {
513 if(kb)
514 {
515 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
516 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
517 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
518 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
519
520 if (!replay_is_replaying())
521 {
522 zc_set_config(ctrl_sect,"key_a",Akey);
523 zc_set_config(ctrl_sect,"key_b",Bkey);
524 zc_set_config(ctrl_sect,"key_s",Skey);
525 zc_set_config(ctrl_sect,"key_l",Lkey);
526 zc_set_config(ctrl_sect,"key_r",Rkey);
527 zc_set_config(ctrl_sect,"key_p",Pkey);
528 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
529 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
530 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
531 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
532 zc_set_config(ctrl_sect,"key_up", DUkey);
533 zc_set_config(ctrl_sect,"key_down", DDkey);
534 zc_set_config(ctrl_sect,"key_left", DLkey);
535 zc_set_config(ctrl_sect,"key_right",DRkey);
536 }
537 }
538 else
539 {
540 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
541 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
542 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
543 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
544 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
545 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
546 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
547 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
548 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
549 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
550 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
551 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
552 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
553 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
554
555 zc_set_config(ctrl_sect,"btn_a",Abtn);
556 zc_set_config(ctrl_sect,"btn_b",Bbtn);
557 zc_set_config(ctrl_sect,"btn_s",Sbtn);
558 zc_set_config(ctrl_sect,"btn_m",Mbtn);
559 zc_set_config(ctrl_sect,"btn_l",Lbtn);
560 zc_set_config(ctrl_sect,"btn_r",Rbtn);
561 zc_set_config(ctrl_sect,"btn_p",Pbtn);
562 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
563 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
564 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
565 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
566
567 zc_set_config(ctrl_sect,"btn_up",DUbtn);
568 zc_set_config(ctrl_sect,"btn_down",DDbtn);
569 zc_set_config(ctrl_sect,"btn_left",DLbtn);
570 zc_set_config(ctrl_sect,"btn_right",DRbtn);
571 }
572 }
573
574 void save_cheatkeys()
575 {
576 char buf[256];
577 for(size_t q = 1; q < Cheat::Last; ++q)
578 {
579 if(!bindable_cheat((Cheat)q)) continue;
580 std::string cheatname = cheat_to_string((Cheat)q);
581 util::lowerstr(cheatname);
582 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
583 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
584 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
585 if(cheatkeys[q][1])
586 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
587 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
588 }
589 }
590
591 304 void save_game_configs()
592 {
593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
304 if (!loaded_game_configs) return;
594
595 304 packfile_password("");
596
597
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
304 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
598 {
599 int o_window_x, o_window_y;
600 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
601 zc_set_config(cfg_sect,"window_x",o_window_x);
602 zc_set_config(cfg_sect,"window_y",o_window_y);
603 }
604
605
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
304 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
606 {
607 window_width = al_get_display_width(all_get_display());
608 window_height = al_get_display_height(all_get_display());
609 zc_set_config(cfg_sect,"window_width",window_width);
610 zc_set_config(cfg_sect,"window_height",window_height);
611 }
612
613 304 zc_set_config(cfg_sect,"load_last",loadlast);
614 304 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
615
616 304 flush_config_file();
617 #ifdef __EMSCRIPTEN__
618 em_sync_fs();
619 #endif
620 304 }
621
622 //----------------------------------------------------------------
623
624 // Timers
625
626 37910 void fps_callback()
627 {
628 37910 lastfps=framecnt;
629 37910 framecnt=0;
630 37910 }
631
632 END_OF_FUNCTION(fps_callback)
633
634 304 int32_t Z_init_timers()
635 {
636 static bool didit = false;
637 const static char *err_str = "Couldn't allocate timer";
638 304 err_str = err_str; //Unused variable warning
639
640
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
304 if(didit)
641 return 1;
642
643 304 didit = true;
644
645 LOCK_VARIABLE(lastfps);
646 LOCK_VARIABLE(framecnt);
647 LOCK_FUNCTION(fps_callback);
648
649
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
650 return 0;
651
652 304 return 1;
653 304 }
654
655 304 void Z_remove_timers()
656 {
657 304 remove_int(fps_callback);
658 304 }
659
660 //----------------------------------------------------------------
661
662 void go()
663 {
664 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
665 }
666
667 void comeback()
668 {
669 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
670 }
671
672 void dump_pal(BITMAP *dest)
673 {
674 for(int32_t i=0; i<256; i++)
675 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
676 }
677
678 //----------------------------------------------------------------
679
680 int game_mouse_index = ZCM_BLANK;
681 static bool system_mouse = false;
682 110 bool sys_mouse()
683 {
684 110 system_mouse = true;
685 110 return MouseSprite::set(ZCM_NORMAL);
686 }
687 1616 bool game_mouse()
688 {
689 1616 system_mouse = false;
690 1616 return MouseSprite::set(game_mouse_index);
691 }
692 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
693 {
694 if(!bmp)
695 return;
696 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
697 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
698 if(bmp->w == scaledw && bmp->h == scaledh)
699 user_scale = false;
700 if(user_scale || sys_recolor)
701 {
702 if(!user_scale) scale = 1;
703 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
704 if(user_scale)
705 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
706 else
707 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
708 if(sys_recolor)
709 recolor_mouse(tmpbmp);
710 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
711 destroy_bitmap(tmpbmp);
712 }
713 else
714 {
715 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
716 }
717 }
718
719 //Handles converting the mouse sprite from the .dat file
720 void recolor_mouse(BITMAP* bmp)
721 {
722 for(int32_t x = 0; x < bmp->w; ++x)
723 {
724 for(int32_t y = 0; y < bmp->h; ++y)
725 {
726 int32_t color = getpixel(bmp, x, y);
727 switch(color)
728 {
729 case dvc(1):
730 color = jwin_pal[jcCURSORMISC];
731 break;
732 case dvc(2):
733 color = jwin_pal[jcCURSOROUTLINE];
734 break;
735 case dvc(3):
736 color = jwin_pal[jcCURSORLIGHT];
737 break;
738 case dvc(5):
739 color = jwin_pal[jcCURSORDARK];
740 break;
741 default:
742 continue;
743 }
744 putpixel(bmp, x, y, color);
745 }
746 }
747 }
748 void load_mouse()
749 {
750 PALETTE pal;
751 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
752 if (!cursor_bitmap)
753 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
754
755 enter_sys_pal();
756 MouseSprite::set(-1);
757 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
758 int32_t sz = 16*scale;
759 for(int32_t j = 0; j < 1; ++j)
760 {
761 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
762 if(zcmouse[j])
763 destroy_bitmap(zcmouse[j]);
764 zcmouse[j] = create_bitmap_ex(8,sz,sz);
765 clear_bitmap(zcmouse[j]);
766 clear_bitmap(tmpbmp);
767 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
768 recolor_mouse(tmpbmp);
769 if(sz!=16)
770 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
771 else
772 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
773 destroy_bitmap(tmpbmp);
774 }
775 if(!hw_palette) hw_palette = &RAMpal;
776 zc_set_palette(*hw_palette);
777
778 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
779 clear_bitmap(blankmouse);
780
781 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
782 MouseSprite::assign(ZCM_BLANK, blankmouse);
783 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
784
785 //Reload the mouse
786 if(system_mouse)
787 sys_mouse();
788 else game_mouse();
789
790 destroy_bitmap(blankmouse);
791 destroy_bitmap(cursor_bitmap);
792 exit_sys_pal();
793 }
794
795 // sets the video mode and initializes the palette and mouse sprite
796 304 bool game_vid_mode(int32_t mode,int32_t wait)
797 {
798
1/2
✓ Branch 0 taken 304 times.
✗ Branch 1 not taken.
304 if (is_headless())
799 304 return true;
800
801 extern int zq_screen_w, zq_screen_h;
802 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
803 {
804 return false;
805 }
806
807 scrx = (resx-320)>>1;
808 scry = (resy-240)>>1;
809 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
810 zcmouse[q] = NULL;
811 load_mouse();
812
813 for(int32_t i=240; i<256; i++)
814 RAMpal[i]=pal_gui[i];
815
816 zc_set_palette(RAMpal);
817 clear_to_color(screen,BLACK);
818
819 rest(wait);
820 return true;
821 304 }
822
823 312 void null_quest()
824 {
825
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 std::string title_assets_path = "modules/classic/title_gfx.dat";
826
2/4
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 312 times.
312 if (get_last_loaded_qstpath() == title_assets_path)
827 return;
828
829 byte skip_flags[4];
830
2/2
✓ Branch 0 taken 312 times.
✓ Branch 1 taken 8112 times.
8424 for (int i = 0; i < skip_max; i++)
831
1/2
✓ Branch 0 taken 8112 times.
✗ Branch 1 not taken.
8112 set_bit(skip_flags, i, 1);
832
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 set_bit(skip_flags, skip_tiles, 0);
833
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 set_bit(skip_flags, skip_csets, 0);
834
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
835
1/2
✓ Branch 0 taken 312 times.
✗ Branch 1 not taken.
312 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
836 312 sfxdat = 1;
837 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
838 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
839 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
840 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
841
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 312 times.
312 }
842
843 312 void init_NES_mode()
844 {
845 312 null_quest();
846 312 }
847
848 //----------------------------------------------------------------
849
850 qword trianglelines[16]=
851 {
852 0x0000000000000000ULL,
853 0xFD00000000000000ULL,
854 0xFDFD000000000000ULL,
855 0xFDFDFD0000000000ULL,
856 0xFDFDFDFD00000000ULL,
857 0xFDFDFDFDFD000000ULL,
858 0xFDFDFDFDFDFD0000ULL,
859 0xFDFDFDFDFDFDFD00ULL,
860 0xFDFDFDFDFDFDFDFDULL,
861 0x00FDFDFDFDFDFDFDULL,
862 0x0000FDFDFDFDFDFDULL,
863 0x000000FDFDFDFDFDULL,
864 0x00000000FDFDFDFDULL,
865 0x0000000000FDFDFDULL,
866 0x000000000000FDFDULL,
867 0x00000000000000FDULL,
868 };
869
870 word screen_triangles[29][32];
871
872 // the ULL suffixes are to prevent this warning:
873 // warning: integer constant is too large for "int32_t" type
874
875 qword triangles[4][16][8]= //[direction][value][line]
876 {
877 {
878 {
879 0x0000000000000000ULL,
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL
887 },
888 {
889 0xFD00000000000000ULL,
890 0x0000000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL
897 },
898 {
899 0xFDFD000000000000ULL,
900 0xFD00000000000000ULL,
901 0x0000000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL
907 },
908 {
909 0xFDFDFD0000000000ULL,
910 0xFDFD000000000000ULL,
911 0xFD00000000000000ULL,
912 0x0000000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL
917 },
918 {
919 0xFDFDFDFD00000000ULL,
920 0xFDFDFD0000000000ULL,
921 0xFDFD000000000000ULL,
922 0xFD00000000000000ULL,
923 0x0000000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL
927 },
928 {
929 0xFDFDFDFDFD000000ULL,
930 0xFDFDFDFD00000000ULL,
931 0xFDFDFD0000000000ULL,
932 0xFDFD000000000000ULL,
933 0xFD00000000000000ULL,
934 0x0000000000000000ULL,
935 0x0000000000000000ULL,
936 0x0000000000000000ULL
937 },
938 {
939 0xFDFDFDFDFDFD0000ULL,
940 0xFDFDFDFDFD000000ULL,
941 0xFDFDFDFD00000000ULL,
942 0xFDFDFD0000000000ULL,
943 0xFDFD000000000000ULL,
944 0xFD00000000000000ULL,
945 0x0000000000000000ULL,
946 0x0000000000000000ULL
947 },
948 {
949 0xFDFDFDFDFDFDFD00ULL,
950 0xFDFDFDFDFDFD0000ULL,
951 0xFDFDFDFDFD000000ULL,
952 0xFDFDFDFD00000000ULL,
953 0xFDFDFD0000000000ULL,
954 0xFDFD000000000000ULL,
955 0xFD00000000000000ULL,
956 0x0000000000000000ULL
957 },
958 {
959 0xFDFDFDFDFDFDFDFDULL,
960 0xFDFDFDFDFDFDFD00ULL,
961 0xFDFDFDFDFDFD0000ULL,
962 0xFDFDFDFDFD000000ULL,
963 0xFDFDFDFD00000000ULL,
964 0xFDFDFD0000000000ULL,
965 0xFDFD000000000000ULL,
966 0xFD00000000000000ULL
967 },
968 {
969 0xFDFDFDFDFDFDFDFDULL,
970 0xFDFDFDFDFDFDFDFDULL,
971 0xFDFDFDFDFDFDFD00ULL,
972 0xFDFDFDFDFDFD0000ULL,
973 0xFDFDFDFDFD000000ULL,
974 0xFDFDFDFD00000000ULL,
975 0xFDFDFD0000000000ULL,
976 0xFDFD000000000000ULL
977 },
978 {
979 0xFDFDFDFDFDFDFDFDULL,
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFD00ULL,
983 0xFDFDFDFDFDFD0000ULL,
984 0xFDFDFDFDFD000000ULL,
985 0xFDFDFDFD00000000ULL,
986 0xFDFDFD0000000000ULL
987 },
988 {
989 0xFDFDFDFDFDFDFDFDULL,
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFD00ULL,
994 0xFDFDFDFDFDFD0000ULL,
995 0xFDFDFDFDFD000000ULL,
996 0xFDFDFDFD00000000ULL
997 },
998 {
999 0xFDFDFDFDFDFDFDFDULL,
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFD00ULL,
1005 0xFDFDFDFDFDFD0000ULL,
1006 0xFDFDFDFDFD000000ULL
1007 },
1008 {
1009 0xFDFDFDFDFDFDFDFDULL,
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFD00ULL,
1016 0xFDFDFDFDFDFD0000ULL
1017 },
1018 {
1019 0xFDFDFDFDFDFDFDFDULL,
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFD00ULL
1027 },
1028 {
1029 0xFDFDFDFDFDFDFDFDULL,
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL
1037 }
1038 },
1039 {
1040 {
1041 0x0000000000000000ULL,
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL
1049 },
1050 {
1051 0x00000000000000FDULL,
1052 0x0000000000000000ULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL
1059 },
1060 {
1061 0x000000000000FDFDULL,
1062 0x00000000000000FDULL,
1063 0x0000000000000000ULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL
1069 },
1070 {
1071 0x0000000000FDFDFDULL,
1072 0x000000000000FDFDULL,
1073 0x00000000000000FDULL,
1074 0x0000000000000000ULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL
1079 },
1080 {
1081 0x00000000FDFDFDFDULL,
1082 0x0000000000FDFDFDULL,
1083 0x000000000000FDFDULL,
1084 0x00000000000000FDULL,
1085 0x0000000000000000ULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL
1089 },
1090 {
1091 0x000000FDFDFDFDFDULL,
1092 0x00000000FDFDFDFDULL,
1093 0x0000000000FDFDFDULL,
1094 0x000000000000FDFDULL,
1095 0x00000000000000FDULL,
1096 0x0000000000000000ULL,
1097 0x0000000000000000ULL,
1098 0x0000000000000000ULL
1099 },
1100 {
1101 0x0000FDFDFDFDFDFDULL,
1102 0x000000FDFDFDFDFDULL,
1103 0x00000000FDFDFDFDULL,
1104 0x0000000000FDFDFDULL,
1105 0x000000000000FDFDULL,
1106 0x00000000000000FDULL,
1107 0x0000000000000000ULL,
1108 0x0000000000000000ULL
1109 },
1110 {
1111 0x00FDFDFDFDFDFDFDULL,
1112 0x0000FDFDFDFDFDFDULL,
1113 0x000000FDFDFDFDFDULL,
1114 0x00000000FDFDFDFDULL,
1115 0x0000000000FDFDFDULL,
1116 0x000000000000FDFDULL,
1117 0x00000000000000FDULL,
1118 0x0000000000000000ULL
1119 },
1120 {
1121 0xFDFDFDFDFDFDFDFDULL,
1122 0x00FDFDFDFDFDFDFDULL,
1123 0x0000FDFDFDFDFDFDULL,
1124 0x000000FDFDFDFDFDULL,
1125 0x00000000FDFDFDFDULL,
1126 0x0000000000FDFDFDULL,
1127 0x000000000000FDFDULL,
1128 0x00000000000000FDULL
1129 },
1130 {
1131 0xFDFDFDFDFDFDFDFDULL,
1132 0xFDFDFDFDFDFDFDFDULL,
1133 0x00FDFDFDFDFDFDFDULL,
1134 0x0000FDFDFDFDFDFDULL,
1135 0x000000FDFDFDFDFDULL,
1136 0x00000000FDFDFDFDULL,
1137 0x0000000000FDFDFDULL,
1138 0x000000000000FDFDULL
1139 },
1140 {
1141 0xFDFDFDFDFDFDFDFDULL,
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0x00FDFDFDFDFDFDFDULL,
1145 0x0000FDFDFDFDFDFDULL,
1146 0x000000FDFDFDFDFDULL,
1147 0x00000000FDFDFDFDULL,
1148 0x0000000000FDFDFDULL
1149 },
1150 {
1151 0xFDFDFDFDFDFDFDFDULL,
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0x00FDFDFDFDFDFDFDULL,
1156 0x0000FDFDFDFDFDFDULL,
1157 0x000000FDFDFDFDFDULL,
1158 0x00000000FDFDFDFDULL
1159 },
1160 {
1161 0xFDFDFDFDFDFDFDFDULL,
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0x00FDFDFDFDFDFDFDULL,
1167 0x0000FDFDFDFDFDFDULL,
1168 0x000000FDFDFDFDFDULL
1169 },
1170 {
1171 0xFDFDFDFDFDFDFDFDULL,
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0x00FDFDFDFDFDFDFDULL,
1178 0x0000FDFDFDFDFDFDULL
1179 },
1180 {
1181 0xFDFDFDFDFDFDFDFDULL,
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0x00FDFDFDFDFDFDFDULL
1189 },
1190 {
1191 0xFDFDFDFDFDFDFDFDULL,
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL
1199 }
1200 },
1201 {
1202 {
1203 0x0000000000000000ULL,
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL
1211 },
1212 {
1213 0x0000000000000000ULL,
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0xFD00000000000000ULL
1221 },
1222 {
1223 0x0000000000000000ULL,
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0xFD00000000000000ULL,
1230 0xFDFD000000000000ULL
1231 },
1232 {
1233 0x0000000000000000ULL,
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0xFD00000000000000ULL,
1239 0xFDFD000000000000ULL,
1240 0xFDFDFD0000000000ULL
1241 },
1242 {
1243 0x0000000000000000ULL,
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0xFD00000000000000ULL,
1248 0xFDFD000000000000ULL,
1249 0xFDFDFD0000000000ULL,
1250 0xFDFDFDFD00000000ULL
1251 },
1252 {
1253 0x0000000000000000ULL,
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL,
1256 0xFD00000000000000ULL,
1257 0xFDFD000000000000ULL,
1258 0xFDFDFD0000000000ULL,
1259 0xFDFDFDFD00000000ULL,
1260 0xFDFDFDFDFD000000ULL
1261 },
1262 {
1263 0x0000000000000000ULL,
1264 0x0000000000000000ULL,
1265 0xFD00000000000000ULL,
1266 0xFDFD000000000000ULL,
1267 0xFDFDFD0000000000ULL,
1268 0xFDFDFDFD00000000ULL,
1269 0xFDFDFDFDFD000000ULL,
1270 0xFDFDFDFDFDFD0000ULL
1271 },
1272 {
1273 0x0000000000000000ULL,
1274 0xFD00000000000000ULL,
1275 0xFDFD000000000000ULL,
1276 0xFDFDFD0000000000ULL,
1277 0xFDFDFDFD00000000ULL,
1278 0xFDFDFDFDFD000000ULL,
1279 0xFDFDFDFDFDFD0000ULL,
1280 0xFDFDFDFDFDFDFD00ULL
1281 },
1282 {
1283 0xFD00000000000000ULL,
1284 0xFDFD000000000000ULL,
1285 0xFDFDFD0000000000ULL,
1286 0xFDFDFDFD00000000ULL,
1287 0xFDFDFDFDFD000000ULL,
1288 0xFDFDFDFDFDFD0000ULL,
1289 0xFDFDFDFDFDFDFD00ULL,
1290 0xFDFDFDFDFDFDFDFDULL
1291 },
1292 {
1293 0xFDFD000000000000ULL,
1294 0xFDFDFD0000000000ULL,
1295 0xFDFDFDFD00000000ULL,
1296 0xFDFDFDFDFD000000ULL,
1297 0xFDFDFDFDFDFD0000ULL,
1298 0xFDFDFDFDFDFDFD00ULL,
1299 0xFDFDFDFDFDFDFDFDULL,
1300 0xFDFDFDFDFDFDFDFDULL
1301 },
1302 {
1303 0xFDFDFD0000000000ULL,
1304 0xFDFDFDFD00000000ULL,
1305 0xFDFDFDFDFD000000ULL,
1306 0xFDFDFDFDFDFD0000ULL,
1307 0xFDFDFDFDFDFDFD00ULL,
1308 0xFDFDFDFDFDFDFDFDULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL
1311 },
1312 {
1313 0xFDFDFDFD00000000ULL,
1314 0xFDFDFDFDFD000000ULL,
1315 0xFDFDFDFDFDFD0000ULL,
1316 0xFDFDFDFDFDFDFD00ULL,
1317 0xFDFDFDFDFDFDFDFDULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL
1321 },
1322 {
1323 0xFDFDFDFDFD000000ULL,
1324 0xFDFDFDFDFDFD0000ULL,
1325 0xFDFDFDFDFDFDFD00ULL,
1326 0xFDFDFDFDFDFDFDFDULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL
1331 },
1332 {
1333 0xFDFDFDFDFDFD0000ULL,
1334 0xFDFDFDFDFDFDFD00ULL,
1335 0xFDFDFDFDFDFDFDFDULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL
1341 },
1342 {
1343 0xFDFDFDFDFDFDFD00ULL,
1344 0xFDFDFDFDFDFDFDFDULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL
1351 },
1352 {
1353 0xFDFDFDFDFDFDFDFDULL,
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL
1361 }
1362 },
1363 {
1364 {
1365 0x0000000000000000ULL,
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL
1373 },
1374 {
1375 0x0000000000000000ULL,
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x00000000000000FDULL
1383 },
1384 {
1385 0x0000000000000000ULL,
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x00000000000000FDULL,
1392 0x000000000000FDFDULL
1393 },
1394 {
1395 0x0000000000000000ULL,
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x00000000000000FDULL,
1401 0x000000000000FDFDULL,
1402 0x0000000000FDFDFDULL
1403 },
1404 {
1405 0x0000000000000000ULL,
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x00000000000000FDULL,
1410 0x000000000000FDFDULL,
1411 0x0000000000FDFDFDULL,
1412 0x00000000FDFDFDFDULL
1413 },
1414 {
1415 0x0000000000000000ULL,
1416 0x0000000000000000ULL,
1417 0x0000000000000000ULL,
1418 0x00000000000000FDULL,
1419 0x000000000000FDFDULL,
1420 0x0000000000FDFDFDULL,
1421 0x00000000FDFDFDFDULL,
1422 0x000000FDFDFDFDFDULL
1423 },
1424 {
1425 0x0000000000000000ULL,
1426 0x0000000000000000ULL,
1427 0x00000000000000FDULL,
1428 0x000000000000FDFDULL,
1429 0x0000000000FDFDFDULL,
1430 0x00000000FDFDFDFDULL,
1431 0x000000FDFDFDFDFDULL,
1432 0x0000FDFDFDFDFDFDULL
1433 },
1434 {
1435 0x0000000000000000ULL,
1436 0x00000000000000FDULL,
1437 0x000000000000FDFDULL,
1438 0x0000000000FDFDFDULL,
1439 0x00000000FDFDFDFDULL,
1440 0x000000FDFDFDFDFDULL,
1441 0x0000FDFDFDFDFDFDULL,
1442 0x00FDFDFDFDFDFDFDULL
1443 },
1444 {
1445 0x00000000000000FDULL,
1446 0x000000000000FDFDULL,
1447 0x0000000000FDFDFDULL,
1448 0x00000000FDFDFDFDULL,
1449 0x000000FDFDFDFDFDULL,
1450 0x0000FDFDFDFDFDFDULL,
1451 0x00FDFDFDFDFDFDFDULL,
1452 0xFDFDFDFDFDFDFDFDULL
1453 },
1454 {
1455 0x000000000000FDFDULL,
1456 0x0000000000FDFDFDULL,
1457 0x00000000FDFDFDFDULL,
1458 0x000000FDFDFDFDFDULL,
1459 0x0000FDFDFDFDFDFDULL,
1460 0x00FDFDFDFDFDFDFDULL,
1461 0xFDFDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL
1463 },
1464 {
1465 0x0000000000FDFDFDULL,
1466 0x00000000FDFDFDFDULL,
1467 0x000000FDFDFDFDFDULL,
1468 0x0000FDFDFDFDFDFDULL,
1469 0x00FDFDFDFDFDFDFDULL,
1470 0xFDFDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL
1473 },
1474 {
1475 0x00000000FDFDFDFDULL,
1476 0x000000FDFDFDFDFDULL,
1477 0x0000FDFDFDFDFDFDULL,
1478 0x00FDFDFDFDFDFDFDULL,
1479 0xFDFDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL
1483 },
1484 {
1485 0x000000FDFDFDFDFDULL,
1486 0x0000FDFDFDFDFDFDULL,
1487 0x00FDFDFDFDFDFDFDULL,
1488 0xFDFDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL
1493 },
1494 {
1495 0x0000FDFDFDFDFDFDULL,
1496 0x00FDFDFDFDFDFDFDULL,
1497 0xFDFDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL
1503 },
1504 {
1505 0x00FDFDFDFDFDFDFDULL,
1506 0xFDFDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL
1513 },
1514 {
1515 0xFDFDFDFDFDFDFDFDULL,
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL
1523 }
1524 }
1525 };
1526
1527 static bool is_opening_screen;
1528 int32_t black_opening_count=0;
1529 int32_t black_opening_x,black_opening_y;
1530 int32_t black_opening_shape;
1531
1532 3274 int32_t choose_opening_shape()
1533 {
1534 // First, count how many bits are set
1535 3274 int32_t numBits=0;
1536 int32_t bitCounter;
1537
1538
2/2
✓ Branch 0 taken 16370 times.
✓ Branch 1 taken 3274 times.
19644 for(int32_t i=0; i<bosMAX; i++)
1539 {
1540
2/2
✓ Branch 0 taken 12880 times.
✓ Branch 1 taken 3490 times.
16370 if(COOLSCROLL&(1<<i))
1541 3490 numBits++;
1542 16370 }
1543
1544 // Shouldn't happen...
1545
1/2
✓ Branch 0 taken 3274 times.
✗ Branch 1 not taken.
3274 if(numBits==0)
1546 return bosCIRCLE;
1547
1548 // Pick a bit
1549 3274 bitCounter=zc_rand()%numBits+1;
1550
1551
2/2
✓ Branch 0 taken 4465 times.
✓ Branch 1 taken 26 times.
4491 for(int32_t i=0; i<bosMAX; i++)
1552 {
1553 // If this bit is set, decrement the bit counter
1554
2/2
✓ Branch 0 taken 1061 times.
✓ Branch 1 taken 3404 times.
4465 if(COOLSCROLL&(1<<i))
1555 3404 bitCounter--;
1556
1557 // When the counter hits 0, return a value based on
1558 // which bit it stopped on.
1559 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1560
2/2
✓ Branch 0 taken 3248 times.
✓ Branch 1 taken 1217 times.
4465 if(bitCounter==0)
1561 3248 return i;
1562 1217 }
1563
1564 // Shouldn't be necessary, but the compiler might complain, at least
1565 26 return bosCIRCLE;
1566 3274 }
1567
1568 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1569 {
1570 739 x -= viewport.x;
1571 739 y -= viewport.y;
1572
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1573
1574 739 int32_t w=framebuf->w, h=framebuf->h;
1575 739 int32_t blockrows=h/8, blockcolumns=32;
1576 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1577
1578
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1579 {
1580
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1581 {
1582
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1583 662144 }
1584 20692 }
1585
1586 739 black_opening_count = 66;
1587 739 black_opening_x = x;
1588 739 black_opening_y = y;
1589 739 lensclk = 0;
1590 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1591
1592
1593
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1594 {
1595 refreshTints();
1596 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1597 }
1598
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1599 {
1600 14 FFCore.warpScriptCheck();
1601
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1602 {
1603 924 draw_screen();
1604 924 advanceframe(true);
1605
1606
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1607 {
1608 break;
1609 }
1610 924 }
1611 14 }
1612 739 }
1613
1614 2555 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1615 {
1616 2555 x -= viewport.x;
1617 2555 y -= viewport.y;
1618
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2545 times.
2555 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1619
1620 2555 int32_t w=framebuf->w, h=framebuf->h;
1621 2555 int32_t blockrows=h/8, blockcolumns=32;
1622 2555 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1623
1624
2/2
✓ Branch 0 taken 71639 times.
✓ Branch 1 taken 2555 times.
74194 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1625 {
1626
2/2
✓ Branch 0 taken 2292448 times.
✓ Branch 1 taken 71639 times.
2364087 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1627 {
1628
2/2
✓ Branch 0 taken 1130168 times.
✓ Branch 1 taken 1162280 times.
2292448 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1629 2292448 }
1630 71639 }
1631
1632 2555 black_opening_count = -66;
1633 2555 black_opening_x = x;
1634 2555 black_opening_y = y;
1635 2555 lensclk = 0;
1636
1/2
✓ Branch 0 taken 2555 times.
✗ Branch 1 not taken.
2555 if(black_opening_shape == bosFADEBLACK)
1637 {
1638 refreshTints();
1639 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1640 }
1641
2/2
✓ Branch 0 taken 370 times.
✓ Branch 1 taken 2185 times.
2555 if(wait)
1642 {
1643 2185 FFCore.warpScriptCheck();
1644
2/2
✓ Branch 0 taken 2184 times.
✓ Branch 1 taken 144221 times.
146405 for(int32_t i=0; i<66; i++)
1645 {
1646 144221 draw_screen();
1647 144221 advanceframe(true);
1648
1649
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 144220 times.
144221 if(Quit)
1650 {
1651 1 break;
1652 }
1653 144220 }
1654 2185 }
1655 2555 }
1656
1657 216506 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1658 {
1659 216506 clear_to_color(tmp_scr,BLACK);
1660 216506 int32_t w=dest->w, h=dest->h;
1661
1662
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20262 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 184628 times.
216506 switch(black_opening_shape)
1663 {
1664 case bosOVAL:
1665 {
1666 9636 double new_w=(w/2)+abs(w/2-x);
1667 9636 double new_h=(h/2)+abs(h/2-y);
1668 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1669 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1670 9636 break;
1671 }
1672
1673 case bosTRIANGLE:
1674 {
1675 1980 double new_w=(w/2)+abs(w/2-x);
1676 1980 double new_h=(h/2)+abs(h/2-y);
1677 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1678 1980 double P2= (PI/2);
1679 1980 double P23=(2*PI/3);
1680 1980 double P43=(4*PI/3);
1681 1980 double Pa= (-4*PI*a/(3*max_a));
1682 1980 double angle=P2+Pa;
1683 1980 double a0=angle;
1684 1980 double a2=angle+P23;
1685 1980 double a4=angle+P43;
1686 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1687 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1688 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1689 0);
1690 1980 break;
1691 }
1692
1693 case bosSMAS:
1694 {
1695
2/2
✓ Branch 0 taken 7194 times.
✓ Branch 1 taken 13068 times.
20262 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1696
1697
2/2
✓ Branch 0 taken 567336 times.
✓ Branch 1 taken 20262 times.
587598 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1698 {
1699
2/2
✓ Branch 0 taken 4538688 times.
✓ Branch 1 taken 567336 times.
5106024 for(int32_t linerow=0; linerow<8; ++linerow)
1700 {
1701 4538688 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1702
1703
2/2
✓ Branch 0 taken 145238016 times.
✓ Branch 1 taken 4538688 times.
149776704 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1704 {
1705 435714048 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1706
6/6
✓ Branch 0 taken 104912184 times.
✓ Branch 1 taken 40325832 times.
✓ Branch 2 taken 95821040 times.
✓ Branch 3 taken 49416976 times.
✓ Branch 4 taken 55495208 times.
✓ Branch 5 taken 40325832 times.
145238016 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1707 145238016 [linerow];
1708 145238016 ++triangleline;
1709 145238016 }
1710 4538688 }
1711 567336 }
1712
1713 20262 break;
1714 }
1715
1716 case bosFADEBLACK:
1717 {
1718 if(black_opening_count<0)
1719 {
1720 black_fade(zc_min(-black_opening_count,63));
1721 }
1722 else if(black_opening_count>0)
1723 {
1724 black_fade(63-zc_max(black_opening_count-3,0));
1725 }
1726 else black_fade(0);
1727 return; //no blitting from tmp_scr!
1728 }
1729
1730 184628 case bosCIRCLE:
1731 default:
1732 {
1733 184628 double new_w=(w/2)+abs(w/2-x);
1734 184628 double new_h=(h/2)+abs(h/2-y);
1735 184628 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1736 //circlefill(tmp_scr,x,y,a<<3,0);
1737 184628 circlefill(tmp_scr,x,y,r,0);
1738 184628 break;
1739 }
1740 }
1741
1742 216506 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1743 216506 }
1744
1745 // fadeamnt is 0-63
1746 void black_fade(int32_t fadeamnt)
1747 {
1748 fadeamnt = _rgb_scale_6[fadeamnt];
1749 for(int32_t i=0; i < 0xEF; i++)
1750 {
1751 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1752 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1753 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1754 }
1755
1756 refreshpal = true;
1757 }
1758
1759 //----------------------------------------------------------------
1760
1761 201329161 bool item_disabled(int32_t item) //is this item disabled?
1762 {
1763
2/2
✓ Branch 0 taken 14361765 times.
✓ Branch 1 taken 186967396 times.
201329161 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1764 }
1765
1766 15615580 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1767 {
1768
2/2
✓ Branch 0 taken 250899 times.
✓ Branch 1 taken 15364681 times.
15615580 if(current_item(item_type, true) >=item)
1769 {
1770 250899 return true;
1771 }
1772
1773 15364681 return false;
1774 15615580 }
1775
1776 48142242 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1777 {
1778
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4412341 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4912947 times.
✓ Branch 6 taken 28722368 times.
✓ Branch 7 taken 9900132 times.
✓ Branch 8 taken 194454 times.
48142242 switch(item_type)
1779 {
1780 case itype_bomb:
1781 case itype_sbomb:
1782 {
1783 int32_t itemid = getItemID(itemsbuf, item_type, it);
1784
1785 if(itemid == -1)
1786 return false;
1787
1788 return (game->get_item(itemid));
1789 }
1790
1791 case itype_clock:
1792 {
1793 4412341 int32_t itemid = getItemID(itemsbuf, item_type, it);
1794
1795
2/4
✓ Branch 0 taken 4412341 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4412341 times.
✗ Branch 3 not taken.
4412341 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1796 return (game->get_item(itemid));
1797 4412341 return Hero.getClock()?1:0;
1798 }
1799
1800 case itype_key:
1801 return (game->get_keys()>0);
1802
1803 case itype_magiccontainer:
1804 return (game->get_maxmagic()>=game->get_mp_per_block());
1805
1806 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1807 {
1808
2/3
✓ Branch 0 taken 332576 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4580371 times.
4912947 switch(it)
1809 {
1810 case -2:
1811 {
1812 for(int32_t i=0; i<MAXLEVELS; i++)
1813 {
1814 if(game->lvlitems[i]&liTRIFORCE)
1815 {
1816 return true;
1817 }
1818 }
1819
1820 return false;
1821 }
1822
1823 case -1:
1824 4580371 return (game->lvlitems[dlevel]&liTRIFORCE);
1825
1826 default:
1827
2/4
✓ Branch 0 taken 332576 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 332576 times.
332576 if(it>=0&&it<MAXLEVELS)
1828 {
1829 332576 return (game->lvlitems[it]&liTRIFORCE);
1830 }
1831
1832 break;
1833 }
1834
1835 return 0;
1836 }
1837
1838 case itype_map: //it: -2=any, -1=current level, other=that level
1839 {
1840
2/3
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28181966 times.
28722368 switch(it)
1841 {
1842 case -2:
1843 {
1844 for(int32_t i=0; i<MAXLEVELS; i++)
1845 {
1846 if(game->lvlitems[i]&liMAP)
1847 {
1848 return true;
1849 }
1850 }
1851
1852 return false;
1853 }
1854
1855 case -1:
1856 28181966 return (game->lvlitems[dlevel]&liMAP)!=0;
1857
1858 default:
1859
2/4
✓ Branch 0 taken 540402 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 540402 times.
540402 if(it>=0&&it<MAXLEVELS)
1860 {
1861 540402 return (game->lvlitems[it]&liMAP)!=0;
1862 }
1863
1864 break;
1865 }
1866
1867 return 0;
1868 }
1869
1870 case itype_compass: //it: -2=any, -1=current level, other=that level
1871 {
1872
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900132 times.
9900132 switch(it)
1873 {
1874 case -2:
1875 {
1876 for(int32_t i=0; i<MAXLEVELS; i++)
1877 {
1878 if(game->lvlitems[i]&liCOMPASS)
1879 {
1880 return true;
1881 }
1882 }
1883
1884 return false;
1885 }
1886
1887 case -1:
1888 9900132 return (game->lvlitems[dlevel]&liCOMPASS)!=0;
1889
1890 default:
1891 if(it>=0&&it<MAXLEVELS)
1892 {
1893 return (game->lvlitems[it]&liCOMPASS)!=0;
1894 }
1895
1896 break;
1897 }
1898 return 0;
1899 }
1900
1901 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1902 {
1903
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 194454 times.
194454 switch(it)
1904 {
1905 case -2:
1906 {
1907 for(int32_t i=0; i<MAXLEVELS; i++)
1908 {
1909 if(game->lvlitems[i]&liBOSSKEY)
1910 {
1911 return true;
1912 }
1913 }
1914
1915 return false;
1916 }
1917
1918 case -1:
1919 194454 return (game->lvlitems[dlevel]&liBOSSKEY)?1:0;
1920
1921 default:
1922 if(it>=0&&it<MAXLEVELS)
1923 {
1924 return (game->lvlitems[it]&liBOSSKEY)?1:0;
1925 }
1926 break;
1927 }
1928 return 0;
1929 }
1930
1931 default:
1932 int32_t itemid = getItemID(itemsbuf, item_type, it);
1933
1934 if(itemid == -1)
1935 return false;
1936
1937 return game->get_item(itemid);
1938 }
1939 48142242 }
1940
1941 150732095 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1942 {
1943
9/9
✓ Branch 0 taken 4412341 times.
✓ Branch 1 taken 115433367 times.
✓ Branch 2 taken 4412341 times.
✓ Branch 3 taken 4412341 times.
✓ Branch 4 taken 4412341 times.
✓ Branch 5 taken 4412341 times.
✓ Branch 6 taken 4412341 times.
✓ Branch 7 taken 4412341 times.
✓ Branch 8 taken 4412341 times.
150732095 switch(item_type)
1944 {
1945 case itype_clock:
1946 {
1947 4412341 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1948
1949
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4412341 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4412341 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1950 return itemsbuf[maxid].fam_type;
1951
1952 4412341 return has_item(itype_clock,1) ? 1 : 0;
1953 }
1954
1955 case itype_key:
1956 4412341 return game->get_keys();
1957
1958 case itype_lkey:
1959 4412341 return game->lvlkeys[get_dlevel()];
1960
1961 case itype_magiccontainer:
1962 4412341 return game->get_maxmagic()/game->get_mp_per_block();
1963
1964 case itype_triforcepiece:
1965 {
1966 4412341 int count=0;
1967
1968
2/2
✓ Branch 0 taken 2259118592 times.
✓ Branch 1 taken 4412341 times.
2263530933 for(int i=0; i<MAXLEVELS; i++)
1969 {
1970 2259118592 count+=(game->lvlitems[i]&liTRIFORCE)?1:0;
1971 2259118592 }
1972
1973 4412341 return count;
1974 }
1975
1976 case itype_map:
1977 {
1978 4412341 int count=0;
1979
1980
2/2
✓ Branch 0 taken 2259118592 times.
✓ Branch 1 taken 4412341 times.
2263530933 for(int i=0; i<MAXLEVELS; i++)
1981 {
1982 2259118592 count+=(game->lvlitems[i]&liMAP)?1:0;
1983 2259118592 }
1984
1985 4412341 return count;
1986 }
1987
1988 case itype_compass:
1989 {
1990 4412341 int count=0;
1991
1992
2/2
✓ Branch 0 taken 2259118592 times.
✓ Branch 1 taken 4412341 times.
2263530933 for(int i=0; i<MAXLEVELS; i++)
1993 {
1994 2259118592 count+=(game->lvlitems[i]&liCOMPASS)?1:0;
1995 2259118592 }
1996
1997 4412341 return count;
1998 }
1999
2000 case itype_bosskey:
2001 {
2002 4412341 int count=0;
2003
2004
2/2
✓ Branch 0 taken 2259118592 times.
✓ Branch 1 taken 4412341 times.
2263530933 for(int i=0; i<MAXLEVELS; i++)
2005 {
2006 2259118592 count+=(game->lvlitems[i]&liBOSSKEY)?1:0;
2007 2259118592 }
2008
2009 4412341 return count;
2010 }
2011
2012 default:
2013 115433367 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2014
2015
2/2
✓ Branch 0 taken 81760278 times.
✓ Branch 1 taken 33673089 times.
115433367 if(maxid == -1)
2016 81760278 return 0;
2017
2018 33673089 return itemsbuf[maxid].fam_type;
2019 }
2020 150732095 }
2021
2022 399 std::map<int32_t, int32_t> itemcache;
2023 399 std::map<int32_t, int32_t> itemcache_cost;
2024
2025 void removeFromItemCache(int32_t itemclass)
2026 {
2027 itemcache.erase(itemclass);
2028 itemcache_cost.erase(itemclass);
2029 cache_tile_mod_clear();
2030 }
2031
2032 13016287 void flushItemCache(bool justcost)
2033 {
2034 13016287 itemcache_cost.clear();
2035
2/2
✓ Branch 0 taken 12942748 times.
✓ Branch 1 taken 73539 times.
13016287 if(!justcost)
2036 73539 itemcache.clear();
2037
2/2
✓ Branch 0 taken 6357672 times.
✓ Branch 1 taken 6585076 times.
12942748 else if(replay_version_check(0,19))
2038 6357672 return;
2039
2040 6658615 cache_tile_mod_clear();
2041
2042 //also fix the active subscreen if items were deleted -DD
2043
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6658615 times.
6658615 if(game != NULL)
2044 {
2045 6658615 verifyBothWeapons();
2046 6658615 refresh_subscr_items();
2047 6658615 }
2048 13016287 }
2049
2050 // This is used often, so it should be as direct as possible.
2051 3005422245 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2052 {
2053 3005422245 bool use_cost_cache = replay_version_check(19);
2054
2/2
✓ Branch 0 taken 2880318837 times.
✓ Branch 1 taken 125103408 times.
3005422245 if(jinx_check)
2055 {
2056 //special case for shields...
2057
3/4
✓ Branch 0 taken 40008153 times.
✓ Branch 1 taken 85095255 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 40008153 times.
125103408 if (itemtype == itype_shield && !HeroShieldClk())
2058 40008153 jinx_check = false;
2059
4/4
✓ Branch 0 taken 52448490 times.
✓ Branch 1 taken 32646765 times.
✓ Branch 2 taken 10856084 times.
✓ Branch 3 taken 41592406 times.
85095255 else if(!(HeroSwordClk() || HeroItemClk()))
2060 41592406 jinx_check = false; //not jinxed
2061 125103408 }
2062
4/4
✓ Branch 0 taken 114318 times.
✓ Branch 1 taken 3005307927 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 112465 times.
3005422245 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2063 3005309780 check_bunny = false;
2064
2/2
✓ Branch 0 taken 2947794139 times.
✓ Branch 1 taken 57628106 times.
3005422245 if(itemtype == itype_ring) checkmagic = true;
2065
4/4
✓ Branch 0 taken 2961919396 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 289651715 times.
✓ Branch 3 taken 25153195 times.
3320227155 if (!jinx_check && !check_bunny
2066
4/4
✓ Branch 0 taken 2961834539 times.
✓ Branch 1 taken 84857 times.
✓ Branch 2 taken 314804910 times.
✓ Branch 3 taken 2647029629 times.
2961919396 && (use_cost_cache || itemtype != itype_ring))
2067 {
2068
4/4
✓ Branch 0 taken 562271865 times.
✓ Branch 1 taken 2374409479 times.
✓ Branch 2 taken 246782816 times.
✓ Branch 3 taken 315489049 times.
2936681344 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2069 2936681344 auto res = cache.find(itemtype);
2070
2071
2/2
✓ Branch 0 taken 2791315364 times.
✓ Branch 1 taken 145365980 times.
2936681344 if(res != cache.end())
2072 2791315364 return res->second;
2073 145365980 }
2074
2075 214106881 int result = -1;
2076 214106881 int highestlevel = -1;
2077
2078
2/2
✓ Branch 0 taken 54811361536 times.
✓ Branch 1 taken 214106881 times.
55025468417 for(int i=0; i<MAXITEMS; i++)
2079 {
2080
6/6
✓ Branch 0 taken 5998492064 times.
✓ Branch 1 taken 48812869472 times.
✓ Branch 2 taken 96465674 times.
✓ Branch 3 taken 5902026390 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96383626 times.
54811361536 if(game->get_item(i) && itemsbuf[i].family==itemtype && !item_disabled(i))
2081 {
2082
4/4
✓ Branch 0 taken 91717669 times.
✓ Branch 1 taken 4665957 times.
✓ Branch 2 taken 2465186 times.
✓ Branch 3 taken 89252483 times.
96383626 if(checkmagic && itemtype != itype_magicring)
2083
2/2
✓ Branch 0 taken 89251782 times.
✓ Branch 1 taken 701 times.
89252483 if(!checkmagiccost(i))
2084 701 continue;
2085
6/6
✓ Branch 0 taken 88786536 times.
✓ Branch 1 taken 7596389 times.
✓ Branch 2 taken 1253652 times.
✓ Branch 3 taken 6342737 times.
✓ Branch 4 taken 4146834 times.
✓ Branch 5 taken 3449555 times.
96382925 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3449555 times.
3449555 if(!(itemsbuf[i].flags & item_jinx_immune))
2087 3449555 continue;
2088
3/4
✓ Branch 0 taken 91665 times.
✓ Branch 1 taken 92841705 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 91665 times.
92933370 if(check_bunny && !checkbunny(i))
2089 91665 continue;
2090
2091
2/2
✓ Branch 0 taken 8440633 times.
✓ Branch 1 taken 84401072 times.
92841705 if(itemsbuf[i].fam_type >= highestlevel)
2092 {
2093 84401072 highestlevel = itemsbuf[i].fam_type;
2094 84401072 result=i;
2095 84401072 }
2096 92841705 }
2097 54807819615 }
2098
2099
4/4
✓ Branch 0 taken 170604032 times.
✓ Branch 1 taken 43502849 times.
✓ Branch 2 taken 84857 times.
✓ Branch 3 taken 170519175 times.
214106881 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2100 {
2101
2/2
✓ Branch 0 taken 128720984 times.
✓ Branch 1 taken 41798191 times.
170519175 if (use_cost_cache)
2102 {
2103
2/2
✓ Branch 0 taken 112839112 times.
✓ Branch 1 taken 15881872 times.
128720984 if (!checkmagic)
2104 15881872 itemcache[itemtype] = result;
2105
6/6
✓ Branch 0 taken 15881872 times.
✓ Branch 1 taken 112839112 times.
✓ Branch 2 taken 687029 times.
✓ Branch 3 taken 15194843 times.
✓ Branch 4 taken 672066 times.
✓ Branch 5 taken 14963 times.
128720984 if (checkmagic || result < 0 || checkmagiccost(result))
2106 128706021 itemcache_cost[itemtype] = result;
2107 128720984 }
2108 else
2109 {
2110 41798191 itemcache[itemtype] = result;
2111 }
2112 170519175 }
2113 214106881 return result;
2114 3005422245 }
2115
2116 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2117 2962421520 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2118 {
2119
2/4
✓ Branch 0 taken 2962421520 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2962421520 times.
2962421520 if(itype < 0 || itype >= itype_max) return -1;
2120
1/2
✓ Branch 0 taken 2962421520 times.
✗ Branch 1 not taken.
2962421520 if(game->OverrideItems[itype] > -2)
2121 {
2122 auto ovid = game->OverrideItems[itype];
2123 if(ovid < 0 || ovid >= MAXITEMS)
2124 return -1;
2125 if(itemsbuf[ovid].family == itype)
2126 {
2127 if(itype == itype_magicring)
2128 checkmagic = false;
2129 else if(itype == itype_ring)
2130 checkmagic = true;
2131
2132 if(checkmagic && !checkmagiccost(ovid))
2133 return -1;
2134
2135 if (jinx_check && !checkitem_jinx(ovid))
2136 {
2137 return -1;
2138 }
2139 return ovid;
2140 }
2141 }
2142 2962421520 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2143
2/2
✓ Branch 0 taken 82102683 times.
✓ Branch 1 taken 2880318837 times.
2962421520 if(!jinx_check) //If not already a jinx-immune-only check...
2144 {
2145 //And the player IS jinxed...
2146
2/2
✓ Branch 0 taken 2837318112 times.
✓ Branch 1 taken 43000725 times.
2880318837 if(HeroIsJinxed())
2147 {
2148 //Then do a jinx-immune-only check here
2149 43000725 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2150 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2151 //Should NOT need a compat rule, as this should always return -1 in old quests.
2152
2/2
✓ Branch 0 taken 3265892 times.
✓ Branch 1 taken 39734833 times.
43000725 if(ret2 > -1) return ret2;
2153 39734833 }
2154 2877052945 }
2155 2959155628 return ret;
2156 2962421520 }
2157
2158 66263524 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2159 {
2160 66263524 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2161
2/2
✓ Branch 0 taken 35465345 times.
✓ Branch 1 taken 30798179 times.
66263524 return (result<0) ? 0 : itemsbuf[result].power;
2162 }
2163
2164 26 int32_t heart_container_id()
2165 {
2166
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2167 {
2168
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].family == itype_heartcontainer)
2169 {
2170 26 return i;
2171 }
2172 728 }
2173 return -1;
2174 26 }
2175
2176 struct tilemod_cache_state_t
2177 {
2178
6/6
✓ Branch 0 taken 4411985 times.
✓ Branch 1 taken 8525591 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8525589 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8525235 times.
21463167 bool operator==(const tilemod_cache_state_t&) const = default;
2179
2180 bool valid;
2181 bool bunny_clock;
2182 bool superman;
2183 int shield;
2184 };
2185 tilemod_cache_state_t tilemod_cache_state;
2186 int32_t tilemod_cache_value;
2187
2188 6660143 void cache_tile_mod_clear()
2189 {
2190 6660143 tilemod_cache_state = {false};
2191 6660143 }
2192
2193 12937576 int32_t item_tile_mod()
2194 {
2195 51750304 tilemod_cache_state_t state = {
2196 .valid = true,
2197 12937576 .bunny_clock = Hero.BunnyClock() != 0,
2198 12937576 .superman = Hero.superman,
2199 12937576 .shield = Hero.active_shield_id,
2200 };
2201
2/2
✓ Branch 0 taken 8525235 times.
✓ Branch 1 taken 4412341 times.
12937576 if (tilemod_cache_state == state)
2202 8525235 return tilemod_cache_value;
2203
2204 4412341 int32_t tile=0;
2205 4412341 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2206
4/4
✓ Branch 0 taken 3999104 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 3079190 times.
✓ Branch 3 taken 919914 times.
4412341 if(check_bombcost || game->get_bombs())
2207 {
2208 3492427 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2209
3/4
✓ Branch 0 taken 3432912 times.
✓ Branch 1 taken 59515 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432912 times.
3492427 if(itemid > -1 && checkbunny(itemid))
2210 3432912 tile+=itemsbuf[itemid].ltm;
2211 3492427 }
2212
2213
4/4
✓ Branch 0 taken 3999104 times.
✓ Branch 1 taken 413237 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3033806 times.
4412341 if(check_bombcost || game->get_sbombs())
2214 {
2215 1378535 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2216
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413478 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378535 if(itemid > -1 && checkbunny(itemid))
2217 965057 tile+=itemsbuf[itemid].ltm;
2218 1378535 }
2219
2220
2/2
✓ Branch 0 taken 4407715 times.
✓ Branch 1 taken 4626 times.
4412341 if(current_item(itype_clock))
2221 {
2222 4626 int32_t itemid =
2223
2/2
✓ Branch 0 taken 4594 times.
✓ Branch 1 taken 32 times.
4626 get_qr(qr_HARDCODED_LITEM_LTMS)
2224 ? iClock
2225 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2226
2/4
✓ Branch 0 taken 4626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4626 times.
4626 if(itemid > -1 && checkbunny(itemid))
2227 4626 tile+=itemsbuf[itemid].ltm;
2228 4626 }
2229
2230
2/2
✓ Branch 0 taken 3766699 times.
✓ Branch 1 taken 645642 times.
4412341 if(current_item(itype_key))
2231 {
2232 645642 int32_t itemid =
2233
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2234 ? iKey
2235 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2236
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2237 645642 tile+=itemsbuf[itemid].ltm;
2238 645642 }
2239
2240
2/2
✓ Branch 0 taken 3911458 times.
✓ Branch 1 taken 500883 times.
4412341 if(current_item(itype_lkey))
2241 {
2242 500883 int32_t itemid =
2243
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86714 times.
500883 get_qr(qr_HARDCODED_LITEM_LTMS)
2244 ? iLevelKey
2245 86714 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2246
2/4
✓ Branch 0 taken 500883 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500883 times.
500883 if(itemid > -1 && checkbunny(itemid))
2247 500883 tile+=itemsbuf[itemid].ltm;
2248 500883 }
2249
2250
2/2
✓ Branch 0 taken 1577873 times.
✓ Branch 1 taken 2834468 times.
4412341 if(current_item(itype_map))
2251 {
2252 2834468 int32_t itemid =
2253
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10634 times.
2834468 get_qr(qr_HARDCODED_LITEM_LTMS)
2254 ? iMap
2255 10634 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2256
2/4
✓ Branch 0 taken 2834468 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834468 times.
2834468 if(itemid > -1 && checkbunny(itemid))
2257 2834468 tile+=itemsbuf[itemid].ltm;
2258 2834468 }
2259
2260
2/2
✓ Branch 0 taken 2100352 times.
✓ Branch 1 taken 2311989 times.
4412341 if(current_item(itype_compass))
2261 {
2262 2311989 int32_t itemid =
2263
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2264 ? iCompass
2265 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2266
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2267 2311989 tile+=itemsbuf[itemid].ltm;
2268 2311989 }
2269
2270
2/2
✓ Branch 0 taken 1325925 times.
✓ Branch 1 taken 3086416 times.
4412341 if(current_item(itype_bosskey))
2271 {
2272 3086416 int32_t itemid =
2273
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2274 ? iBossKey
2275 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2276
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2277 3086416 tile+=itemsbuf[itemid].ltm;
2278 3086416 }
2279
2280
2/2
✓ Branch 0 taken 48269 times.
✓ Branch 1 taken 4364072 times.
4412341 if(current_item(itype_magiccontainer))
2281 {
2282 4364072 int32_t itemid =
2283
2/2
✓ Branch 0 taken 3896229 times.
✓ Branch 1 taken 467843 times.
4364072 get_qr(qr_HARDCODED_LITEM_LTMS)
2284 ? iMagicC
2285 467843 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2286
3/4
✓ Branch 0 taken 4364072 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4364055 times.
4364072 if(itemid > -1 && checkbunny(itemid))
2287 4364055 tile+=itemsbuf[itemid].ltm;
2288 4364072 }
2289
2290
2/2
✓ Branch 0 taken 1305861 times.
✓ Branch 1 taken 3106480 times.
4412341 if(current_item(itype_triforcepiece))
2291 {
2292 3106480 int32_t itemid =
2293
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2294 ? iTriforce
2295 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2296
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2297 3106480 tile+=itemsbuf[itemid].ltm;
2298 3106480 }
2299
2300
2/2
✓ Branch 0 taken 2259118592 times.
✓ Branch 1 taken 4412341 times.
2263530933 for(int32_t i=0; i<itype_max; i++)
2301 {
2302
2/2
✓ Branch 0 taken 2019475968 times.
✓ Branch 1 taken 239642624 times.
2259118592 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2303 {
2304
2/2
✓ Branch 0 taken 4680520 times.
✓ Branch 1 taken 234962104 times.
239642624 switch(i)
2305 {
2306 case itype_bomb:
2307 case itype_sbomb:
2308 case itype_clock:
2309 case itype_key:
2310 case itype_lkey:
2311 case itype_map:
2312 case itype_compass:
2313 case itype_bosskey:
2314 case itype_magiccontainer:
2315 case itype_triforcepiece:
2316 4680520 continue; //already handled
2317 }
2318 234962104 }
2319 2254438072 int32_t itemid = current_item_id(i,false);
2320
2/2
✓ Branch 0 taken 2250025731 times.
✓ Branch 1 taken 4412341 times.
2254438072 if(i == itype_shield)
2321 4412341 itemid = getCurrentShield(false);
2322
2323
4/4
✓ Branch 0 taken 115594005 times.
✓ Branch 1 taken 2138844067 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115594004 times.
2254438072 if(itemid < 0 || !checkbunny(itemid))
2324 2138844068 continue;
2325
2326 115594004 itemdata const& itm = itemsbuf[itemid];
2327
2328
2/2
✓ Branch 0 taken 111894080 times.
✓ Branch 1 taken 3699924 times.
115594004 switch(itm.family)
2329 {
2330 case itype_shield:
2331
1/2
✓ Branch 0 taken 3699924 times.
✗ Branch 1 not taken.
3699924 if(itm.flags & item_flag9) //active shield
2332 {
2333 if(!usingActiveShield(itemid))
2334 {
2335 tile+=itm.misc6; //'Inactive PTM'
2336 continue;
2337 }
2338 }
2339 3699924 break;
2340 }
2341
2342 115594004 tile+=itm.ltm;
2343 115594004 }
2344
2345 4412341 tilemod_cache_value = tile;
2346 4412341 tilemod_cache_state = state;
2347 4412341 return tile;
2348 12937576 }
2349
2350 12937576 int32_t bunny_tile_mod()
2351 {
2352
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12935706 times.
12937576 if(Hero.BunnyClock())
2353 {
2354 1870 return game->get_bunny_ltm();
2355 }
2356 12935706 return 0;
2357 12937576 }
2358
2359 // Hints are drawn on a separate layer to combo reveals.
2360 // TODO: move out of zc_sys.cpp, weird place for this code.
2361 20058 void draw_lens_under(BITMAP *dest, bool layer)
2362 {
2363 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2364 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2365 //Lens flag 3: Don't show armos/chest/dive items
2366 //Lens flag 4: Show Raft Paths
2367 //Lens flag 5: Show Invisible Enemies
2368
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2369
2370 20058 int32_t strike_hint_table[11]=
2371 {
2372 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2373 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2374 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2375 };
2376
2377 {
2378 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2379 20058 int32_t tempitem, tempweapon=0;
2380 20058 strike_hint=strike_hint_table[strike_hint_counter];
2381
2382
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2383 {
2384 599 strike_hint_timer=0;
2385 599 strike_hint_counter=((strike_hint_counter+1)%11);
2386 599 }
2387
2388 20058 ++strike_hint_timer;
2389
2390 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2391 3530208 mapscr* scr = rpos_handle.scr;
2392 7306676 auto [x, y] = rpos_handle.xy();
2393 7060416 y += playing_field_offset;
2394
2395 3530208 int32_t tempitemx=-16, tempitemy=-16;
2396 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2397
2398
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2399 {
2400 7060416 int32_t checkflag=0;
2401
2402
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2403 {
2404 3530208 checkflag = rpos_handle.cflag();
2405 3530208 }
2406 else
2407 {
2408 3530208 checkflag = rpos_handle.sflag();
2409 }
2410
2411
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2412 {
2413
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2414 {
2415
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2416 906 }
2417 else
2418 {
2419 192 checkflag = strike_hint;
2420 }
2421 1098 }
2422
2423
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2424 {
2425 case 0:
2426 case mfZELDA:
2427 case mfPUSHED:
2428 case mfENEMY0:
2429 case mfENEMY1:
2430 case mfENEMY2:
2431 case mfENEMY3:
2432 case mfENEMY4:
2433 case mfENEMY5:
2434 case mfENEMY6:
2435 case mfENEMY7:
2436 case mfENEMY8:
2437 case mfENEMY9:
2438 case mfSINGLE:
2439 case mfSINGLE16:
2440 case mfNOENEMY:
2441 case mfTRAP_H:
2442 case mfTRAP_V:
2443 case mfTRAP_4:
2444 case mfTRAP_LR:
2445 case mfTRAP_UD:
2446 case mfNOGROUNDENEMY:
2447 case mfNOBLOCKS:
2448 case mfSCRIPT1:
2449 case mfSCRIPT2:
2450 case mfSCRIPT3:
2451 case mfSCRIPT4:
2452 case mfSCRIPT5:
2453 case mfSCRIPT6:
2454 case mfSCRIPT7:
2455 case mfSCRIPT8:
2456 case mfSCRIPT9:
2457 case mfSCRIPT10:
2458 case mfSCRIPT11:
2459 case mfSCRIPT12:
2460 case mfSCRIPT13:
2461 case mfSCRIPT14:
2462 case mfSCRIPT15:
2463 case mfSCRIPT16:
2464 case mfSCRIPT17:
2465 case mfSCRIPT18:
2466 case mfSCRIPT19:
2467 case mfSCRIPT20:
2468 case mfPITHOLE:
2469 case mfPITFALLFLOOR:
2470 case mfLAVA:
2471 case mfICE:
2472 case mfICEDAMAGE:
2473 case mfDAMAGE1:
2474 case mfDAMAGE2:
2475 case mfDAMAGE4:
2476 case mfDAMAGE8:
2477 case mfDAMAGE16:
2478 case mfDAMAGE32:
2479 case mfFREEZEALL:
2480 case mfFREZEALLANSFFCS:
2481 case mfFREEZEFFCSOLY:
2482 case mfSCRITPTW1TRIG:
2483 case mfSCRITPTW2TRIG:
2484 case mfSCRITPTW3TRIG:
2485 case mfSCRITPTW4TRIG:
2486 case mfSCRITPTW5TRIG:
2487 case mfSCRITPTW6TRIG:
2488 case mfSCRITPTW7TRIG:
2489 case mfSCRITPTW8TRIG:
2490 case mfSCRITPTW9TRIG:
2491 case mfSCRITPTW10TRIG:
2492 case mfTROWEL:
2493 case mfTROWELNEXT:
2494 case mfTROWELSPECIALITEM:
2495 case mfSLASHPOT:
2496 case mfLIFTPOT:
2497 case mfLIFTORSLASH:
2498 case mfLIFTROCK:
2499 case mfLIFTROCKHEAVY:
2500 case mfDROPITEM:
2501 case mfSPECIALITEM:
2502 case mfDROPKEY:
2503 case mfDROPLKEY:
2504 case mfDROPCOMPASS:
2505 case mfDROPMAP:
2506 case mfDROPBOSSKEY:
2507 case mfSPAWNNPC:
2508 case mfSWITCHHOOK:
2509 case mfSIDEVIEWLADDER:
2510 case mfSIDEVIEWPLATFORM:
2511 case mfNOENEMYSPAWN:
2512 case mfENEMYALL:
2513 case mfNOMIRROR:
2514 case mfUNSAFEGROUND:
2515 case mf168:
2516 case mf169:
2517 case mf170:
2518 case mf171:
2519 case mf172:
2520 case mf173:
2521 case mf174:
2522 case mf175:
2523 case mf176:
2524 case mf177:
2525 case mf178:
2526 case mf179:
2527 case mf180:
2528 case mf181:
2529 case mf182:
2530 case mf183:
2531 case mf184:
2532 case mf185:
2533 case mf186:
2534 case mf187:
2535 case mf188:
2536 case mf189:
2537 case mf190:
2538 case mf191:
2539 case mf192:
2540 case mf193:
2541 case mf194:
2542 case mf195:
2543 case mf196:
2544 case mf197:
2545 case mf198:
2546 case mf199:
2547 case mf200:
2548 case mf201:
2549 case mf202:
2550 case mf203:
2551 case mf204:
2552 case mf205:
2553 case mf206:
2554 case mf207:
2555 case mf208:
2556 case mf209:
2557 case mf210:
2558 case mf211:
2559 case mf212:
2560 case mf213:
2561 case mf214:
2562 case mf215:
2563 case mf216:
2564 case mf217:
2565 case mf218:
2566 case mf219:
2567 case mf220:
2568 case mf221:
2569 case mf222:
2570 case mf223:
2571 case mf224:
2572 case mf225:
2573 case mf226:
2574 case mf227:
2575 case mf228:
2576 case mf229:
2577 case mf230:
2578 case mf231:
2579 case mf232:
2580 case mf233:
2581 case mf234:
2582 case mf235:
2583 case mf236:
2584 case mf237:
2585 case mf238:
2586 case mf239:
2587 case mf240:
2588 case mf241:
2589 case mf242:
2590 case mf243:
2591 case mf244:
2592 case mf245:
2593 case mf246:
2594 case mf247:
2595 case mf248:
2596 case mf249:
2597 case mf250:
2598 case mf251:
2599 case mf252:
2600 case mf253:
2601 case mf254:
2602 case mfEXTENDED:
2603 6911766 break;
2604
2605 case mfPUSHUD:
2606 case mfPUSHLR:
2607 case mfPUSH4:
2608 case mfPUSHU:
2609 case mfPUSHD:
2610 case mfPUSHL:
2611 case mfPUSHR:
2612 case mfPUSHUDNS:
2613 case mfPUSHLRNS:
2614 case mfPUSH4NS:
2615 case mfPUSHUNS:
2616 case mfPUSHDNS:
2617 case mfPUSHLNS:
2618 case mfPUSHRNS:
2619 case mfPUSHUDINS:
2620 case mfPUSHLRINS:
2621 case mfPUSH4INS:
2622 case mfPUSHUINS:
2623 case mfPUSHDINS:
2624 case mfPUSHLINS:
2625 case mfPUSHRINS:
2626
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2627
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2628 {
2629 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2630 }
2631
2632
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2633
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2634 {
2635
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2636 {
2637
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2638 {
2639 case cPUSH_HEAVY:
2640 case cPUSH_HW:
2641 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2642 144 tempitemx=x, tempitemy=y;
2643
2644
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2645 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2646
2647 72 break;
2648
2649 case cPUSH_HEAVY2:
2650 case cPUSH_HW2:
2651 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2652 126 tempitemx=x, tempitemy=y;
2653
2654
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2655 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2656
2657 63 break;
2658 }
2659 1032 }
2660 2520 }
2661
2662 3258 break;
2663
2664 case mfWHISTLE:
2665
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2666 {
2667 tempitem=getItemID(itemsbuf,itype_whistle,1);
2668
2669 if(tempitem<0) break;
2670
2671 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2672 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2673 {
2674 tempitemx=x;
2675 tempitemy=y;
2676 }
2677
2678 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2679 }
2680
2681 2418 break;
2682
2683 //Why is this here?
2684 case mfFAIRY:
2685 case mfMAGICFAIRY:
2686 case mfALLFAIRY:
2687 if(hints)
2688 {
2689 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2690
2691 if(tempitem < 0) break;
2692
2693 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2694 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2695 {
2696 tempitemx=x;
2697 tempitemy=y;
2698 }
2699
2700 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2701 }
2702
2703 break;
2704
2705 case mfANYFIRE:
2706
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2707 {
2708
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2709 252 }
2710 else
2711 {
2712 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2713
2714
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2715
2716
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2717
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2718 {
2719 189 tempitemx=x;
2720 189 tempitemy=y;
2721 189 }
2722
2723 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2724 }
2725
2726 504 break;
2727
2728 case mfSTRONGFIRE:
2729 if(!hints)
2730 {
2731 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2732 }
2733 else
2734 {
2735 tempitem=getItemID(itemsbuf,itype_candle,2);
2736
2737 if(tempitem<0) break;
2738
2739 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2740 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2741 {
2742 tempitemx=x;
2743 tempitemy=y;
2744 }
2745
2746 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2747 }
2748
2749 break;
2750
2751 case mfMAGICFIRE:
2752 if(!hints)
2753 {
2754 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2755 }
2756 else
2757 {
2758 tempitem=getItemID(itemsbuf,itype_wand,1);
2759
2760 if(tempitem<0) break;
2761
2762 tempweapon=wFire;
2763
2764 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2765 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2766 {
2767 tempitemx=x;
2768 tempitemy=y;
2769 }
2770 else
2771 {
2772 tempweaponx=x;
2773 tempweapony=y;
2774 }
2775
2776 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2777 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2778 }
2779
2780 break;
2781
2782 case mfDIVINEFIRE:
2783 if(!hints)
2784 {
2785 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2786 }
2787 else
2788 {
2789 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2790
2791 if(tempitem<0) break;
2792
2793 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2794 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2795 {
2796 tempitemx=x;
2797 tempitemy=y;
2798 }
2799
2800 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2801 }
2802
2803 break;
2804
2805 case mfARROW:
2806
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2807 {
2808
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2809 732 }
2810 else
2811 {
2812 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2813
2814
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2815
2816
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2817
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2818 {
2819 61 tempitemx=x;
2820 61 tempitemy=y;
2821 61 }
2822
2823 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2824 }
2825
2826 814 break;
2827
2828 case mfSARROW:
2829 if(!hints)
2830 {
2831 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2832 }
2833 else
2834 {
2835 tempitem=getItemID(itemsbuf,itype_arrow,2);
2836
2837 if(tempitem<0) break;
2838
2839 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2840 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2841 {
2842 tempitemx=x;
2843 tempitemy=y;
2844 }
2845
2846 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2847 }
2848
2849 break;
2850
2851 case mfGARROW:
2852 if(!hints)
2853 {
2854 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2855 }
2856 else
2857 {
2858 tempitem=getItemID(itemsbuf,itype_arrow,3);
2859
2860 if(tempitem<0) break;
2861
2862 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2863 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2864 {
2865 tempitemx=x;
2866 tempitemy=y;
2867 }
2868
2869 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2870 }
2871
2872 break;
2873
2874 case mfBOMB:
2875
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2876 {
2877
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2878 76 }
2879 else
2880 {
2881 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2882 17 tempweapon = wLitBomb;
2883
2884 //if (tempitem<0) break;
2885
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2886
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2887 {
2888 12 tempweaponx=x;
2889 12 tempweapony=y;
2890 12 }
2891
2892 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2893 }
2894
2895 93 break;
2896
2897 case mfSBOMB:
2898
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2899 {
2900
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2901 48 }
2902 else
2903 {
2904 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2905 //if (tempitem<0) break;
2906 48 tempweapon = wLitSBomb;
2907
2908
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2909
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2910 {
2911 36 tempweaponx=x;
2912 36 tempweapony=y;
2913 36 }
2914
2915 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2916 }
2917
2918 96 break;
2919
2920 case mfARMOS_SECRET:
2921
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2922 {
2923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2924 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2925 12 }
2926 24 break;
2927
2928 case mfBRANG:
2929
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2930 {
2931
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2932 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2933 20 }
2934 else
2935 {
2936 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2937
2938
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2939
2940
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2941
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2942 {
2943 4 tempitemx=x;
2944 4 tempitemy=y;
2945 4 }
2946
2947 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2948 }
2949
2950 25 break;
2951
2952 case mfMBRANG:
2953 if(!hints)
2954 {
2955 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2956 }
2957 else
2958 {
2959 tempitem=getItemID(itemsbuf,itype_brang,2);
2960
2961 if(tempitem<0) break;
2962
2963 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2964 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2965 {
2966 tempitemx=x;
2967 tempitemy=y;
2968 }
2969
2970 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2971 }
2972
2973 break;
2974
2975 case mfFBRANG:
2976 if(!hints)
2977 {
2978 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2979 }
2980 else
2981 {
2982 tempitem=getItemID(itemsbuf,itype_brang,3);
2983
2984 if(tempitem<0) break;
2985
2986 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2987 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2988 {
2989 tempitemx=x;
2990 tempitemy=y;
2991 }
2992
2993 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2994 }
2995
2996 break;
2997
2998 case mfWANDMAGIC:
2999
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3000 {
3001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3002 138 }
3003 else
3004 {
3005 tempitem=getItemID(itemsbuf,itype_wand,1);
3006
3007 if(tempitem<0) break;
3008
3009 tempweapon=itemsbuf[tempitem].wpn3;
3010
3011 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3012 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3013 {
3014 tempitemx=x;
3015 tempitemy=y;
3016 }
3017 else
3018 {
3019 tempweaponx=x;
3020 tempweapony=y;
3021 --lens_hint_weapon[wMagic][4];
3022
3023 if(lens_hint_weapon[wMagic][4]<-8)
3024 {
3025 lens_hint_weapon[wMagic][4]=8;
3026 }
3027 }
3028
3029 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3030 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3031 }
3032
3033 138 break;
3034
3035 case mfREFMAGIC:
3036
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3037 {
3038 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3039 }
3040 else
3041 {
3042 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3043
3044
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3045
3046 16 tempweapon=ewMagic;
3047
3048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3049
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3050 {
3051 13 tempitemx=x;
3052 13 tempitemy=y;
3053 13 }
3054 else
3055 {
3056 3 tempweaponx=x;
3057 3 tempweapony=y;
3058
3059
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3060 {
3061 1 --lens_hint_weapon[ewMagic][4];
3062 1 }
3063 else
3064 {
3065 2 ++lens_hint_weapon[ewMagic][4];
3066 }
3067
3068
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3069 {
3070 lens_hint_weapon[ewMagic][2]=up;
3071 }
3072
3073
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3074 {
3075 2 lens_hint_weapon[ewMagic][2]=down;
3076 2 }
3077 }
3078
3079 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3080 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3081 }
3082
3083 16 break;
3084
3085 case mfREFFIREBALL:
3086
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3087 {
3088 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3089 }
3090 else
3091 {
3092 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3093
3094
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3095
3096 16 tempweapon=ewFireball;
3097
3098
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3099
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3100 {
3101 12 tempitemx=x;
3102 12 tempitemy=y;
3103 12 tempweaponx=x;
3104 12 tempweapony=y;
3105 12 ++lens_hint_weapon[ewFireball][3];
3106
3107
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3108 {
3109 1 lens_hint_weapon[ewFireball][3]=-8;
3110 1 lens_hint_weapon[ewFireball][4]=8;
3111 1 }
3112
3113
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3114 {
3115 8 ++lens_hint_weapon[ewFireball][4];
3116 8 }
3117 else
3118 {
3119 4 --lens_hint_weapon[ewFireball][4];
3120 }
3121 12 }
3122
3123 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3124 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3125 }
3126
3127 16 break;
3128
3129 case mfSWORD:
3130
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3131 {
3132 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3133 }
3134 else
3135 {
3136 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3137
3138
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3139
3140
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3141
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3142 {
3143 5 tempitemx=x;
3144 5 tempitemy=y;
3145 5 }
3146
3147 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3148 }
3149
3150 7 break;
3151
3152 case mfWSWORD:
3153 if(!hints)
3154 {
3155 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3156 }
3157 else
3158 {
3159 tempitem=getItemID(itemsbuf,itype_sword,2);
3160
3161 if(tempitem<0) break;
3162
3163 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3164 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3165 {
3166 tempitemx=x;
3167 tempitemy=y;
3168 }
3169
3170 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3171 }
3172
3173 break;
3174
3175 case mfMSWORD:
3176 if(!hints)
3177 {
3178 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3179 }
3180 else
3181 {
3182 tempitem=getItemID(itemsbuf,itype_sword,3);
3183
3184 if(tempitem<0) break;
3185
3186 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3187 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3188 {
3189 tempitemx=x;
3190 tempitemy=y;
3191 }
3192
3193 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3194 }
3195
3196 break;
3197
3198 case mfXSWORD:
3199 if(!hints)
3200 {
3201 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3202 }
3203 else
3204 {
3205 tempitem=getItemID(itemsbuf,itype_sword,4);
3206
3207 if(tempitem<0) break;
3208
3209 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3210 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3211 {
3212 tempitemx=x;
3213 tempitemy=y;
3214 }
3215
3216 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3217 }
3218
3219 break;
3220
3221 case mfSWORDBEAM:
3222
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3223 {
3224 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3225 }
3226 else
3227 {
3228 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3229
3230
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3231
3232
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3233
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3234 {
3235 11 tempitemx=x;
3236 11 tempitemy=y;
3237 11 }
3238
3239 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3240 }
3241
3242 16 break;
3243
3244 case mfWSWORDBEAM:
3245 if(!hints)
3246 {
3247 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3248 }
3249 else
3250 {
3251 tempitem=getItemID(itemsbuf,itype_sword,2);
3252
3253 if(tempitem<0) break;
3254
3255 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3256 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3257 {
3258 tempitemx=x;
3259 tempitemy=y;
3260 }
3261
3262 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3263 }
3264
3265 break;
3266
3267 case mfMSWORDBEAM:
3268 if(!hints)
3269 {
3270 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3271 }
3272 else
3273 {
3274 tempitem=getItemID(itemsbuf,itype_sword,3);
3275
3276 if(tempitem<0) break;
3277
3278 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3279 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3280 {
3281 tempitemx=x;
3282 tempitemy=y;
3283 }
3284
3285 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3286 }
3287
3288 break;
3289
3290 case mfXSWORDBEAM:
3291 if(!hints)
3292 {
3293 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3294 }
3295 else
3296 {
3297 tempitem=getItemID(itemsbuf,itype_sword,4);
3298
3299 if(tempitem<0) break;
3300
3301 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3302 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3303 {
3304 tempitemx=x;
3305 tempitemy=y;
3306 }
3307
3308 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3309 }
3310
3311 break;
3312
3313 case mfHOOKSHOT:
3314
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3315 {
3316 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3317 }
3318 else
3319 {
3320 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3321
3322
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3323
3324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3325
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3326 {
3327 12 tempitemx=x;
3328 12 tempitemy=y;
3329 12 }
3330
3331 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3332 }
3333
3334 17 break;
3335
3336 case mfWAND:
3337
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3338 {
3339 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3340 }
3341 else
3342 {
3343 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3344
3345
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3346
3347
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3348
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3349 {
3350 28 tempitemx=x;
3351 28 tempitemy=y;
3352 28 }
3353
3354 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3355 }
3356
3357 35 break;
3358
3359 case mfHAMMER:
3360
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3361 {
3362 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3363 }
3364 else
3365 {
3366 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3367
3368
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3369
3370
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3371
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3372 {
3373 13 tempitemx=x;
3374 13 tempitemy=y;
3375 13 }
3376
3377 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3378 }
3379
3380 17 break;
3381
3382 case mfARMOS_ITEM:
3383 case mfDIVE_ITEM:
3384
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, mSPECIALITEM) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3385 {
3386 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3387 2602 }
3388 2602 break;
3389
3390 case 16:
3391 case 17:
3392 case 18:
3393 case 19:
3394 case 20:
3395 case 21:
3396 case 22:
3397 case 23:
3398 case 24:
3399 case 25:
3400 case 26:
3401 case 27:
3402 case 28:
3403 case 29:
3404 case 30:
3405 case 31:
3406
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3407
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3408 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3409
3410 108898 break;
3411 case mfSECRETSNEXT:
3412 if(!hints)
3413 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3414 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3415
3416 break;
3417
3418 case mfSTRIKE:
3419
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3420 {
3421 906 goto special;
3422 }
3423 else
3424 {
3425 break;
3426 }
3427
3428 28750 default: goto special;
3429
3430 special:
3431
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3432 {
3433
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3434 {
3435 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3436 4954 }
3437 6604 }
3438
3439 29656 break;
3440 }
3441 7060416 }
3442 3530208 });
3443
3444 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3445 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3446
3447 40116 offx -= viewport.x;
3448 40116 offy -= viewport.y;
3449 40116 offy += playing_field_offset;
3450
3451
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3452 {
3453
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3454 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3455
3456
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3457 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3458
3459
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3460 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3461
3462
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3463 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3464
3465
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3466 {
3467 129 showbombeddoor(scr, dest, 0, offx, offy);
3468 43 }
3469
3470
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3471 {
3472 117 showbombeddoor(scr, dest, 1, offx, offy);
3473 39 }
3474
3475
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3476 {
3477 18 showbombeddoor(scr, dest, 2, offx, offy);
3478 6 }
3479
3480
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3481 {
3482 111 showbombeddoor(scr, dest, 3, offx, offy);
3483 37 }
3484 10029 }
3485
3486
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3487 {
3488
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3489 {
3490
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3491 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3492 1123 }
3493 else
3494 {
3495
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3496 {
3497 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3498 48 int32_t tempitemx=-16+offx;
3499 48 int32_t tempitemy=-16+offy-playing_field_offset;
3500
3501
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3502
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3503 {
3504 48 tempitemx=scr->stairx+offx;
3505 48 tempitemy=scr->stairy+offy;
3506 24 }
3507
3508 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3509 48 }
3510 }
3511 2034 }
3512 20058 });
3513 }
3514 20058 }
3515
3516 9690 void draw_lens_over()
3517 {
3518 9690 int w = 288;
3519 9690 int h = 240;
3520
3521
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3522 static int32_t last_width = -1;
3523 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3524
3525 // Only redraw the circle if the size has changed
3526
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3527 {
3528 20 clear_to_color(lens_scr, BLACK);
3529 20 circlefill(lens_scr, w, h, width, 0);
3530 20 circle(lens_scr, w, h, width+2, 0);
3531 20 circle(lens_scr, w, h, width+5, 0);
3532 20 last_width=width;
3533 20 }
3534
3535 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3536 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3537 9690 }
3538
3539 37027243 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3540 {
3541 37027243 BITMAP* bmp = *bmp_ptr;
3542
3/4
✓ Branch 0 taken 37027243 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37027237 times.
✓ Branch 3 taken 6 times.
37027243 if (bmp->w == w && bmp->h == h)
3543 37027237 return;
3544
3545 6 int depth = bitmap_color_depth(bmp);
3546 6 destroy_bitmap(bmp);
3547 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3548 37027243 }
3549
3550 31797 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3551 {
3552
4/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 31792 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✗ Branch 5 not taken.
31797 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3553 31797 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3554
3555 31797 clear_to_color(wavebuf, BLACK);
3556 31797 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3557
3558 int32_t ofs;
3559
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 31797 times.
31797 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3560
4/6
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
✓ Branch 4 taken 494 times.
✓ Branch 5 taken 31303 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3561 31797 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3562
2/4
✓ Branch 0 taken 31797 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 31797 times.
31797 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3563 31797 int32_t i=frame%amp2;
3564
3565
2/2
✓ Branch 0 taken 5341896 times.
✓ Branch 1 taken 31797 times.
5373693 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3566 {
3567
3/4
✓ Branch 0 taken 2670948 times.
✓ Branch 1 taken 2670948 times.
✓ Branch 2 taken 2670948 times.
✗ Branch 3 not taken.
5341896 if(j&1 && interpol)
3568 {
3569 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3570 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3571 }
3572 else
3573 {
3574 5341896 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3575 }
3576
3577
1/2
✓ Branch 0 taken 5341896 times.
✗ Branch 1 not taken.
5341896 if(ofs)
3578 {
3579
2/2
✓ Branch 0 taken 1367525376 times.
✓ Branch 1 taken 5341896 times.
1372867272 for(int32_t k=0; k<256; k++)
3580 {
3581 1367525376 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3582 1367525376 }
3583 5341896 }
3584 5341896 }
3585 31797 }
3586
3587 28224 void draw_fuzzy(int32_t fuzz)
3588 // draws from right half of scrollbuf to framebuf
3589 {
3590 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3591 byte *start, *si, *di;
3592
3593
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28224 times.
28224 if(fuzz<1)
3594 fuzz = 1;
3595
3596 28224 xstep = 128%fuzz;
3597
3598
2/2
✓ Branch 0 taken 5880 times.
✓ Branch 1 taken 22344 times.
28224 if(xstep > 0)
3599 22344 xstep = fuzz-xstep;
3600
3601 28224 ystep = 112%fuzz;
3602
3603
2/2
✓ Branch 0 taken 8232 times.
✓ Branch 1 taken 19992 times.
28224 if(ystep > 0)
3604 19992 ystep = fuzz-ystep;
3605
3606 28224 firsty = 1;
3607
3608
2/2
✓ Branch 0 taken 28224 times.
✓ Branch 1 taken 1018416 times.
1046640 for(y=0; y<framebuf->h;)
3609 {
3610 1018416 start = &(scrollbuf_old->line[y][256]);
3611
3612
4/4
✓ Branch 0 taken 1004304 times.
✓ Branch 1 taken 6336288 times.
✓ Branch 2 taken 6322176 times.
✓ Branch 3 taken 1018416 times.
7340592 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3613 {
3614 6322176 si = start;
3615 6322176 di = &(framebuf->line[y+dy][0]);
3616 6322176 i = xstep;
3617 6322176 firstx = 1;
3618
3619
2/2
✓ Branch 0 taken 1618477056 times.
✓ Branch 1 taken 6322176 times.
1624799232 for(dx=0; dx<framebuf->w; dx++)
3620 {
3621 1618477056 *(di++) = *si;
3622
3623
2/2
✓ Branch 0 taken 1363746048 times.
✓ Branch 1 taken 254731008 times.
1618477056 if(++i >= fuzz)
3624 {
3625
2/2
✓ Branch 0 taken 248408832 times.
✓ Branch 1 taken 6322176 times.
254731008 if(!firstx)
3626 248408832 si += fuzz;
3627 else
3628 {
3629 6322176 si += fuzz-xstep;
3630 6322176 firstx = 0;
3631 }
3632
3633 254731008 i = 0;
3634 254731008 }
3635 1618477056 }
3636 6322176 }
3637
3638
2/2
✓ Branch 0 taken 990192 times.
✓ Branch 1 taken 28224 times.
1018416 if(!firsty)
3639 990192 y += fuzz;
3640 else
3641 {
3642 28224 y += ystep;
3643 28224 ystep = fuzz;
3644 28224 firsty = 0;
3645 }
3646 }
3647 28224 }
3648
3649 18497723 void updatescr(bool allowwavy)
3650 {
3651
4/6
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 18497419 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 304 times.
✓ Branch 4 taken 304 times.
✗ Branch 5 not taken.
18497723 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3652
4/6
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 18497419 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 304 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 304 times.
18497723 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3653 18497723 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3654 18497723 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3655
3656
2/2
✓ Branch 0 taken 18469622 times.
✓ Branch 1 taken 28101 times.
18497723 if(toogam)
3657 {
3658 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3659 28101 }
3660
3661
1/2
✓ Branch 0 taken 18497723 times.
✗ Branch 1 not taken.
18497723 if(Showpal)
3662 dump_pal(framebuf);
3663
3664
2/2
✓ Branch 0 taken 17980826 times.
✓ Branch 1 taken 516897 times.
18497723 if(!Playing)
3665 516897 black_opening_count=0;
3666
3667
2/2
✓ Branch 0 taken 18329991 times.
✓ Branch 1 taken 167732 times.
18497723 if(black_opening_count<0) //shape is opening up
3668 {
3669 167732 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3670
3671
2/4
✓ Branch 0 taken 167732 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 167732 times.
167732 if(Advance||(!Paused))
3672 {
3673 167732 ++black_opening_count;
3674 167732 }
3675 167732 }
3676
2/2
✓ Branch 0 taken 18281217 times.
✓ Branch 1 taken 48774 times.
18329991 else if(black_opening_count>0) //shape is closing
3677 {
3678 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3679
3680
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3681 {
3682 48774 --black_opening_count;
3683 48774 }
3684 48774 }
3685
3686
3/4
✓ Branch 0 taken 18284497 times.
✓ Branch 1 taken 213226 times.
✓ Branch 2 taken 18284497 times.
✗ Branch 3 not taken.
18497723 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3687 {
3688 black_opening_shape = bosCIRCLE;
3689 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3690 refreshTints();
3691 refreshpal=true;
3692 }
3693
3694
2/2
✓ Branch 0 taken 17864756 times.
✓ Branch 1 taken 632967 times.
18497723 if(refreshpal)
3695 {
3696 632967 refreshpal=false;
3697 632967 RAMpal[253] = _RGB(0,0,0);
3698 632967 RAMpal[254] = _RGB(255,255,255);
3699 632967 hw_palette = &RAMpal;
3700 632967 update_hw_pal = true;
3701 632967 refresh_rgb_tables();
3702 632967 }
3703
3704 18497723 bool clearwavy = (wavy <= 0);
3705
3706
2/2
✓ Branch 0 taken 8341 times.
✓ Branch 1 taken 18489382 times.
18497723 if(wavy <= 0)
3707 {
3708 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3709 18489382 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3710 18489382 }
3711
3712 18497723 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3713
3714
6/6
✓ Branch 0 taken 32047 times.
✓ Branch 1 taken 18465676 times.
✓ Branch 2 taken 31925 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 31797 times.
18497723 if(wavy && Playing && allowwavy)
3715 {
3716 31797 draw_wavy(framebuf, wavybuf, wavy,false);
3717 31797 }
3718
3719
2/2
✓ Branch 0 taken 18489382 times.
✓ Branch 1 taken 8341 times.
18497723 if(clearwavy)
3720 18489382 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3721
2/4
✓ Branch 0 taken 8341 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8341 times.
8341 else if(Playing && !Paused)
3722 8341 wavy--; // Wavy was set by a script. Decrement it.
3723
3724
3/4
✓ Branch 0 taken 17980826 times.
✓ Branch 1 taken 516897 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17980826 times.
18497723 if(Playing && !Paused)
3725 17980826 ++light_wave_clk;
3726
3727
6/6
✓ Branch 0 taken 17980826 times.
✓ Branch 1 taken 516897 times.
✓ Branch 2 taken 260021 times.
✓ Branch 3 taken 17720805 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260003 times.
18497723 if(Playing && msg_active && !screenscrolling)
3728 {
3729
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 259936 times.
260003 if(!(msg_bg_display_buf->clip))
3730 259936 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3731
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 259936 times.
260003 if(!(msg_portrait_display_buf->clip))
3732 259936 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3733
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 259936 times.
260003 if(!(msg_txt_display_buf->clip))
3734 259936 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3735 260003 }
3736
3737
3/4
✓ Branch 0 taken 18497723 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18304105 times.
✓ Branch 3 taken 193618 times.
18497723 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3738
3739
2/2
✓ Branch 0 taken 18309378 times.
✓ Branch 1 taken 188345 times.
18497723 if(nosubscr)
3740 {
3741 188345 clear_to_color(panorama, 0);
3742 188345 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3743 188345 }
3744
3745 //TODO: Optimize blit 'overcalls' -Gleeok
3746
2/2
✓ Branch 0 taken 188345 times.
✓ Branch 1 taken 18309378 times.
18497723 BITMAP *source = nosubscr ? panorama : wavybuf;
3747 18497723 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3748
3749 18497723 update_hw_screen();
3750 18497723 }
3751
3752 //----------------------------------------------------------------
3753
3754 static PALETTE syspal;
3755 int32_t onGUISnapshot()
3756 {
3757 char buf[200];
3758 int32_t num=0;
3759 do
3760 {
3761 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3762 }
3763 while(num<99999 && exists(buf));
3764
3765 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3766 InfoDialog("Error", "Failed to save snapshot").show();
3767
3768 return D_O_K;
3769 }
3770
3771 int32_t onNonGUISnapshot()
3772 {
3773 PALETTE temppal;
3774 get_palette(temppal);
3775 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3776
3777 char buf[200];
3778 int32_t num=0;
3779
3780 do
3781 {
3782 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3783 }
3784 while(num<99999 && exists(buf));
3785
3786 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3787 {
3788 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3789 clear_to_color(b,0);
3790 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3791 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3792 destroy_bitmap(b);
3793 }
3794 else
3795 {
3796 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3797 }
3798
3799 return D_O_K;
3800 }
3801
3802 int32_t onSnapshot()
3803 {
3804 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3805 {
3806 onGUISnapshot();
3807 }
3808 else
3809 {
3810 onNonGUISnapshot();
3811 }
3812
3813 return D_O_K;
3814 }
3815
3816 int32_t onSaveMapPic()
3817 {
3818 char buf[200];
3819 int32_t num=0;
3820 BITMAP* _screen_draw_buffer = NULL;
3821 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3822
3823 do
3824 {
3825 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3826 }
3827 while(num<99999 && exists(buf));
3828
3829 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3830 clear_to_color(mappic, BLACK);
3831
3832 if(!mappic)
3833 {
3834 enter_sys_pal();
3835 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3836 exit_sys_pal();
3837 return D_O_K;;
3838 }
3839
3840 clear_to_color(_screen_draw_buffer, BLACK);
3841
3842 auto prev_viewport = viewport;
3843 viewport.x = 0;
3844 viewport.y = 0;
3845
3846 // draw the map
3847
3848 for(int32_t y=0; y<8; y++)
3849 {
3850 for(int32_t x=0; x<16; x++)
3851 {
3852 if (!displayOnMap(x, y))
3853 continue;
3854
3855 int screen = map_scr_xy_to_index(x, y);
3856 auto scrs = loadscr2(screen);
3857 mapscr* scr = &scrs[0];
3858 if (!scr->is_valid())
3859 continue;
3860
3861 screen_handles_t screen_handles;
3862 for (int i = 0; i <= 6; i++)
3863 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3864
3865 int xx = 0;
3866 int yy = -playing_field_offset;
3867
3868 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3869 {
3870 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3871 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3872 }
3873
3874 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3875 {
3876 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3877 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3878 }
3879
3880 if(lenscheck(scr,0))
3881 putscr(scr, _screen_draw_buffer, 0, 0);
3882 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3883 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3884 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3885
3886 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3887 {
3888 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3889 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3890 }
3891
3892 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3893 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3894 {
3895 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3896 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3897 {
3898 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3899 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3900 }
3901 }
3902
3903 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3904 {
3905 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3906 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3907 }
3908
3909 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3910 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3911 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3912 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3913 {
3914 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3915 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3916 }
3917 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3918 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3919 if(replay_version_check(40))
3920 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3921 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3923 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3924
3925 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3926 }
3927 }
3928
3929 viewport = prev_viewport;
3930 save_bitmap(buf,mappic,RAMpal);
3931 destroy_bitmap(mappic);
3932 destroy_bitmap(_screen_draw_buffer);
3933 return D_O_K;
3934 }
3935
3936 55 void f_Quit(int32_t type)
3937 {
3938
2/4
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 55 times.
✗ Branch 3 not taken.
55 if(type==qQUIT && !Playing)
3939 return;
3940
3941 55 bool from_menu = is_sys_pal;
3942
3943
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
3944 {
3945 55 music_pause();
3946 55 pause_all_sfx();
3947 55 sys_mouse();
3948 55 }
3949 55 enter_sys_pal();
3950 55 clear_keybuf();
3951
3952
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 13 times.
55 if (replay_version_check(0, 10))
3953 13 replay_poll();
3954
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if (replay_is_replaying())
3955 55 replay_peek_quit();
3956
3957
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if (!replay_is_replaying())
3958 switch(type)
3959 {
3960 case qQUIT:
3961 onQuit();
3962 break;
3963
3964 case qRESET:
3965 onReset();
3966 break;
3967
3968 case qEXIT:
3969 onExit();
3970 break;
3971 }
3972
3973
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(Quit)
3974 {
3975 55 kill_sfx();
3976 55 music_stop();
3977 55 exit_sys_pal();
3978 55 update_hw_screen();
3979 55 }
3980 else
3981 {
3982 exit_sys_pal();
3983 if(!from_menu)
3984 {
3985 music_resume();
3986 resume_all_sfx();
3987 }
3988 }
3989
3990
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(!from_menu)
3991 55 game_mouse();
3992 55 eat_buttons();
3993
3994 55 zc_readrawkey(KEY_ESC);
3995
3996 55 zc_readrawkey(KEY_ENTER);
3997 55 }
3998
3999 //----------------------------------------------------------------
4000
4001 int32_t onNoWalls()
4002 {
4003 cheats_enqueue(Cheat::Walls);
4004 return D_O_K;
4005 }
4006
4007 int32_t onIgnoreSideview()
4008 {
4009 cheats_enqueue(Cheat::IgnoreSideView);
4010 return D_O_K;
4011 }
4012
4013 18496351 int32_t input_idle(bool checkmouse)
4014 {
4015 static int32_t mx, my, mz, mb;
4016
4017
4/6
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4953791 times.
✓ Branch 3 taken 13542560 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4953791 times.
23450142 if(keypressed() || zc_key_pressed() ||
4018
4/8
✓ Branch 0 taken 4953791 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4953791 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4953791 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4953791 times.
✗ Branch 7 not taken.
4953791 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4019 {
4020 13542560 idle_count = 0;
4021
4022
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13542560 times.
13542560 if(active_count < MAX_ACTIVE)
4023 {
4024 13542560 ++active_count;
4025 13542560 }
4026 13542560 }
4027
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4953791 times.
4953791 else if(idle_count < MAX_IDLE)
4028 {
4029 4953791 ++idle_count;
4030 4953791 active_count = 0;
4031 4953791 }
4032
4033 18496351 mx = mouse_x;
4034 18496351 my = mouse_y;
4035 18496351 mz = mouse_z;
4036 18496351 mb = mouse_b;
4037
4038 18496351 return idle_count;
4039 }
4040
4041 int32_t onGoFast()
4042 {
4043 cheats_enqueue(Cheat::Fast);
4044 return D_O_K;
4045 }
4046
4047 int32_t onKillCheat()
4048 {
4049 cheats_enqueue(Cheat::Kill);
4050 return D_O_K;
4051 }
4052
4053 int32_t onSecretsCheat()
4054 {
4055 cheats_enqueue(Cheat::TrigSecrets);
4056 return D_O_K;
4057 }
4058 int32_t onSecretsCheatPerm()
4059 {
4060 cheats_enqueue(Cheat::TrigSecretsPerm);
4061 return D_O_K;
4062 }
4063
4064 int32_t onShowLayer0()
4065 {
4066 show_layers[0] = !show_layers[0];
4067 return D_O_K;
4068 }
4069 int32_t onShowLayer1()
4070 {
4071 show_layers[1] = !show_layers[1];
4072 return D_O_K;
4073 }
4074 int32_t onShowLayer2()
4075 {
4076 show_layers[2] = !show_layers[2];
4077 return D_O_K;
4078 }
4079 int32_t onShowLayer3()
4080 {
4081 show_layers[3] = !show_layers[3];
4082 return D_O_K;
4083 }
4084 int32_t onShowLayer4()
4085 {
4086 show_layers[4] = !show_layers[4];
4087 return D_O_K;
4088 }
4089 int32_t onShowLayer5()
4090 {
4091 show_layers[5] = !show_layers[5];
4092 return D_O_K;
4093 }
4094 int32_t onShowLayer6()
4095 {
4096 show_layers[6] = !show_layers[6];
4097 return D_O_K;
4098 }
4099 int32_t onShowLayerO()
4100 {
4101 show_layer_over=!show_layer_over;
4102 return D_O_K;
4103 }
4104 int32_t onShowLayerP()
4105 {
4106 show_layer_push=!show_layer_push;
4107 return D_O_K;
4108 }
4109 int32_t onShowLayerS()
4110 {
4111 show_sprites=!show_sprites;
4112 return D_O_K;
4113 }
4114 int32_t onShowLayerF()
4115 {
4116 show_ffcs=!show_ffcs;
4117 return D_O_K;
4118 }
4119 int32_t onShowLayerW()
4120 {
4121 show_walkflags=!show_walkflags;
4122 if(show_walkflags)
4123 show_effectflags = false;
4124 return D_O_K;
4125 }
4126 int32_t onShowLayerE()
4127 {
4128 show_effectflags=!show_effectflags;
4129 if(show_effectflags)
4130 show_walkflags = false;
4131 return D_O_K;
4132 }
4133 int32_t onShowFFScripts()
4134 {
4135 show_ff_scripts=!show_ff_scripts;
4136 return D_O_K;
4137 }
4138 int32_t onShowHitboxes()
4139 {
4140 show_hitboxes=!show_hitboxes;
4141 return D_O_K;
4142 }
4143 int32_t onShowInfoOpacity()
4144 {
4145 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4146 zc_set_config("zc","debug_info_opacity",info_opacity);
4147 return D_O_K;
4148 }
4149
4150 int32_t onLightSwitch()
4151 {
4152 cheats_enqueue(Cheat::Light);
4153 return D_O_K;
4154 }
4155
4156 int32_t onGoTo();
4157 int32_t onGoToComplete();
4158
4159 18496351 bool handle_close_btn_quit()
4160 {
4161
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(close_button_quit)
4162 {
4163 close_button_quit=false;
4164 f_Quit(qEXIT);
4165 }
4166 18496351 return (exiting_program = Quit==qEXIT);
4167 }
4168
4169 18496351 void syskeys()
4170 {
4171 18496351 update_system_keys();
4172
4173 int32_t oldtitle_version;
4174
4175 18496351 poll_joystick();
4176
4177 18496351 handle_close_btn_quit();
4178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
18496351 if(Quit == qEXIT) return;
4179
4180
2/10
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18496351 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18496351 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4181 {
4182 System();
4183 }
4184
4185 18496351 mouse_down=gui_mouse_b();
4186
4187
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(zc_read_system_key(KEY_F1))
4188 {
4189 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4190 {
4191 halt=!halt;
4192 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4193 }
4194 else
4195 {
4196 Throttlefps=!Throttlefps;
4197 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4198 }
4199 }
4200
4201
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(zc_read_system_key(KEY_F2))
4202 {
4203 ShowFPS=!ShowFPS;
4204 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4205 }
4206
4207
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18496351 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4208
4209
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18496351 if(zc_read_system_key(KEY_F4) && Playing)
4210 {
4211 Paused=true;
4212 Advance=true;
4213 }
4214
4215
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(zc_read_system_key(KEY_F6)) onTryQuit();
4216
4217 #ifndef ALLEGRO_MACOSX
4218
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4219
4220
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4221 #else
4222 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4223
4224 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4225 #endif
4226
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18496351 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4227
4228
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if (zc_read_system_key(KEY_F12))
4229 {
4230 onSnapshot();
4231 }
4232
4233
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18496351 if(debug_enabled && zc_read_system_key(KEY_TAB))
4234 set_debug(!get_debug());
4235
4236
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(CheatModifierKeys())
4237 {
4238 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4239 {
4240 if(!bindable_cheat(c))
4241 continue;
4242 if(get_debug() || cheat >= cheat_lvl(c))
4243 {
4244 if(checkcheat(c))
4245 cheats_hit_bind(c);
4246 }
4247 }
4248 }
4249
4250
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(volkeys)
4251 {
4252 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4253
4254 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4255
4256 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4257
4258 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4259 }
4260
4261
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18496351 if(!get_debug() || !SystemKeys || replay_is_replaying())
4262 18496351 goto bottom;
4263
4264 if(zc_readkey(KEY_P)) Paused=!Paused;
4265
4266 if(zc_readkey(KEY_A))
4267 {
4268 Paused=true;
4269 Advance=true;
4270 }
4271
4272 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4273 #ifndef ALLEGRO_MACOSX
4274 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4275
4276 if(zc_readkey(KEY_F7))
4277 {
4278 Matrix(ss_speed, ss_density, 0);
4279 game_pal();
4280 }
4281 #else
4282 // The reason these are different on Mac in the first place is that
4283 // the OS doesn't let us use F9 and F10...
4284 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4285
4286 if(zc_readkey(KEY_F9))
4287 {
4288 Matrix(ss_speed, ss_density, 0);
4289 game_pal();
4290 }
4291 #endif
4292 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4293 {
4294 //change containers
4295 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4296 {
4297 //magic containers
4298 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4299 {
4300 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4301 }
4302 else
4303 {
4304 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4305 }
4306 }
4307 else
4308 {
4309 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4310 {
4311 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4312 }
4313 else
4314 {
4315 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4316 }
4317 }
4318 }
4319
4320 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4321 {
4322 //change containers
4323 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4324 {
4325 //magic containers
4326 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4327 {
4328 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4329 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4330 //heart containers
4331 }
4332 else
4333 {
4334 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4335 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4336 }
4337 }
4338 else
4339 {
4340 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4341 {
4342 game->set_magic(zc_max(game->get_magic()-1,0));
4343 }
4344 else
4345 {
4346 game->set_life(zc_max(game->get_life()-1,0));
4347 }
4348 }
4349 }
4350
4351 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4352
4353 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4354
4355 verifyBothWeapons();
4356
4357 bottom:
4358
4359
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(input_idle(true) > after_time())
4360 {
4361 Matrix(ss_speed, ss_density, 0);
4362 game_pal();
4363 }
4364 18496351 }
4365
4366 1137394 void checkQuitKeys()
4367 {
4368 #ifndef ALLEGRO_MACOSX
4369
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1137394 times.
1137394 if(key[KEY_F9]) f_Quit(qRESET);
4370
4371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1137394 times.
1137394 if(key[KEY_F10]) f_Quit(qEXIT);
4372 #else
4373 if(key[KEY_F7]) f_Quit(qRESET);
4374
4375 if(key[KEY_F8]) f_Quit(qEXIT);
4376 #endif
4377 1137394 }
4378
4379 18496551 bool CheatModifierKeys()
4380 {
4381 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4382 // to trigger cheats.
4383
2/2
✓ Branch 0 taken 18496251 times.
✓ Branch 1 taken 300 times.
18496551 if (replay_is_replaying())
4384 18496251 return false;
4385
4386
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4387
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4388
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4389 {
4390
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4391 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4392 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4393 {
4394 return true;
4395 }
4396 }
4397 100 return false;
4398 18496351 }
4399
4400 //99:05:54, for some reason?
4401 #define OLDMAXTIME 21405240
4402 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4403 #define MAXTIME 1944000000
4404
4405 // (qr, value)
4406 399 static std::queue<std::pair<int, bool>> change_qr_queue;
4407
4408 7 void enqueue_qr_change(int qr, bool value)
4409 {
4410 7 change_qr_queue.push({qr, value});
4411 7 }
4412
4413 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4414 // and soon executed here.
4415 // During playing back a replay file, the replay system adds to the same queue and
4416 // is executed here too.
4417 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4418 // could be later extended to all QRs (perhaps as a cheat).
4419 18496763 void process_enqueued_qr_changes()
4420 {
4421
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18496662 times.
18496763 if (replay_is_replaying())
4422 18496662 replay_do_qrs();
4423
4424
2/2
✓ Branch 0 taken 18496763 times.
✓ Branch 1 taken 7 times.
18496770 while (!change_qr_queue.empty())
4425 {
4426 28 auto [qr, value] = change_qr_queue.front();
4427 7 change_qr_queue.pop();
4428
4429 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4430 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4431 14 _qrs_unpacked[qr] = value;
4432 7 apply_qr_rule(qr);
4433
4434
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4435 2 replay_step_qr(qr, value);
4436 }
4437 18496763 }
4438
4439 18497723 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4440 {
4441
1/2
✓ Branch 0 taken 18497723 times.
✗ Branch 1 not taken.
18497723 if(zcmusic!=NULL)
4442 {
4443 zcmusic_poll();
4444 }
4445 18497723 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4446
4447 18497723 updatescr(allowwavy);
4448
4449 18497723 Advance=false;
4450
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18497723 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18497723 times.
18497723 while(Paused && !Advance && !Quit)
4451 {
4452 // have to call this, otherwise we'll get an infinite loop
4453 syskeys();
4454 if(allowF6Script)
4455 {
4456 FFCore.runF6Engine();
4457 }
4458
4459 #ifdef _WIN32
4460
4461 if(use_dwm_flush)
4462 {
4463 do_DwmFlush();
4464 }
4465
4466 #endif
4467
4468 // to keep music playing
4469 if(zcmusic!=NULL)
4470 {
4471 zcmusic_poll();
4472 }
4473
4474 update_hw_screen();
4475 }
4476
4477
2/2
✓ Branch 0 taken 18496390 times.
✓ Branch 1 taken 1333 times.
18497723 if(Quit)
4478 1333 return;
4479
4480
3/4
✓ Branch 0 taken 17979805 times.
✓ Branch 1 taken 516585 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 17979805 times.
18496390 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4481 17979805 game->change_time(1);
4482
4483 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4484
4485 18496390 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4486
2/2
✓ Branch 0 taken 8696775 times.
✓ Branch 1 taken 9799615 times.
18496390 if (replay_version_check(0, 16))
4487 9799615 should_reset_down_state = replay_version_check(11, 16);
4488
2/2
✓ Branch 0 taken 15084865 times.
✓ Branch 1 taken 3411525 times.
18496390 if (should_reset_down_state)
4489 {
4490
2/2
✓ Branch 0 taken 61407450 times.
✓ Branch 1 taken 3411525 times.
64818975 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4491 61407450 down_control_states[i] = raw_control_state[i];
4492 3411525 }
4493
4494
2/2
✓ Branch 0 taken 39 times.
✓ Branch 1 taken 18496351 times.
18496390 if (replay_is_active())
4495 {
4496
2/2
✓ Branch 0 taken 1545418 times.
✓ Branch 1 taken 16950933 times.
18496351 if (replay_version_check(3))
4497 16950933 replay_poll();
4498
4499
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11017440 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18496351 if (replay_version_check(11) || replay_version_check(6, 8))
4500 11117975 replay_peek_input();
4501 18496351 }
4502
4503 18496390 process_enqueued_qr_changes();
4504
4505 18496390 load_control_called_this_frame = false;
4506
4507 18496390 poll_keyboard();
4508 18496390 update_keys();
4509
4510 18496390 ++frame;
4511
4512
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 18496251 times.
18496390 if (replay_is_replaying())
4513 18496251 replay_do_cheats();
4514 18496390 syskeys();
4515
4516 // The mouse variables can change from the mouse thread at anytime during a frame,
4517 // so save the result at the start so that replaying is consistent.
4518 18496390 script_mouse_x = gui_mouse_x();
4519 18496390 script_mouse_y = gui_mouse_y();
4520 18496390 script_mouse_z = mouse_z;
4521 18496390 script_mouse_b = mouse_b;
4522
4523 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4524 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4525 // approach here means it doesn't matter which call adds the cheat.
4526 18496390 cheats_execute_queued();
4527
4528
2/2
✓ Branch 0 taken 139 times.
✓ Branch 1 taken 18496251 times.
18496390 if (replay_is_replaying())
4529 18496251 replay_peek_quit();
4530
2/2
✓ Branch 0 taken 18496335 times.
✓ Branch 1 taken 55 times.
18496390 if (GameFlags & GAMEFLAG_TRYQUIT)
4531 55 replay_step_quit(0);
4532
2/2
✓ Branch 0 taken 3324 times.
✓ Branch 1 taken 18493066 times.
18496390 if(allowF6Script)
4533 18493066 FFCore.runF6Engine();
4534
2/2
✓ Branch 0 taken 760 times.
✓ Branch 1 taken 18495630 times.
18496390 if (Quit)
4535 760 replay_step_quit(Quit);
4536
4537 #ifdef _WIN32
4538
4539 if(use_dwm_flush)
4540 {
4541 do_DwmFlush();
4542 }
4543
4544 #endif
4545
4546
2/2
✓ Branch 0 taken 208647 times.
✓ Branch 1 taken 18287743 times.
18496390 if(sfxcleanup)
4547 18287743 sfx_cleanup();
4548
4549 18496390 jit_poll();
4550
4551 #ifdef __EMSCRIPTEN__
4552 // Yield the main thread back to the browser occasionally.
4553 if (is_headless())
4554 {
4555 static int rate = 10000;
4556 static int force_yield = rate;
4557 if (force_yield++ >= rate)
4558 {
4559 force_yield = 0;
4560 emscripten_sleep(0);
4561 }
4562 }
4563 #endif
4564
4565
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18496290 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18496390 if (zqtesting_mode && test_mode_auto_restart)
4566 {
4567 static auto last_write_time = fs::last_write_time(qstpath);
4568 static auto last_check = std::chrono::system_clock::now();
4569
4570 if (std::chrono::system_clock::now() - last_check > 200ms)
4571 {
4572 last_check = std::chrono::system_clock::now();
4573 auto write_time = fs::last_write_time(qstpath);
4574 if (last_write_time != write_time)
4575 {
4576 last_write_time = write_time;
4577 disableClickToFreeze = false;
4578 Quit = qRESET;
4579 replay_quit();
4580 }
4581 }
4582 }
4583 18497723 }
4584
4585 589 void zapout()
4586 {
4587 589 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4588 589 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4589
4590 589 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4591 589 script_drawing_commands.Clear();
4592
4593 // zap out
4594
2/2
✓ Branch 0 taken 589 times.
✓ Branch 1 taken 14136 times.
14725 for(int32_t i=1; i<=24; i++)
4595 {
4596 14136 draw_fuzzy(i);
4597 14136 advanceframe(true);
4598
4599
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14136 times.
14136 if(Quit)
4600 {
4601 break;
4602 }
4603 14136 }
4604 589 }
4605
4606 587 void zapin()
4607 {
4608 587 FFCore.warpScriptCheck();
4609 587 draw_screen();
4610 587 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4611 587 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4612
4613 // zap out
4614 587 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4615
2/2
✓ Branch 0 taken 587 times.
✓ Branch 1 taken 14088 times.
14675 for(int32_t i=24; i>=1; i--)
4616 {
4617 14088 draw_fuzzy(i);
4618 14088 advanceframe(true);
4619
4620
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14088 times.
14088 if(Quit)
4621 {
4622 break;
4623 }
4624 14088 }
4625 587 }
4626
4627
4628 235 void wavyout(bool showhero)
4629 {
4630 235 draw_screen(showhero);
4631
4632 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4633 235 clear_to_color(wavebuf,0);
4634 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4635
4636 static PALETTE wavepal;
4637
4638 int32_t ofs;
4639 235 int32_t amplitude=8;
4640
4641 235 int32_t wavelength=4;
4642 235 int height = viewport.visible_height(show_bottom_8px);
4643 235 double palpos=0, palstep=4, palstop=126;
4644
4645 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4646
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4647 {
4648
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4649 {
4650 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4651 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4652 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4653 2520320 }
4654
4655 9845 palpos+=palstep;
4656
4657
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4658 {
4659 9845 hw_palette = &wavepal;
4660 9845 update_hw_pal = true;
4661 9845 }
4662 else
4663 {
4664 hw_palette = &RAMpal;
4665 update_hw_pal = true;
4666 }
4667
4668
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4669 {
4670
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4671 {
4672 423413760 ofs=0;
4673
4674
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4675 {
4676 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4677 103224320 }
4678
4679 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4680 423413760 }
4681 1653960 }
4682
4683 9845 advanceframe(true);
4684
4685
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4686 1 break;
4687 9844 }
4688
4689 235 destroy_bitmap(wavebuf);
4690
4691 235 hw_palette = &RAMpal;
4692 235 update_hw_pal = true;
4693 235 }
4694
4695 232 void wavyin()
4696 {
4697 232 draw_screen();
4698
4699 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4700 232 clear_to_color(wavebuf,0);
4701 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4702
4703 static PALETTE wavepal;
4704
4705 232 refreshpal=false;
4706 int32_t ofs;
4707 232 int32_t amplitude=8;
4708 232 int32_t wavelength=4;
4709 232 int height = viewport.visible_height(show_bottom_8px);
4710 232 double palpos=height, palstep=4, palstop=126;
4711
4712 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4713
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4714 {
4715
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4716 {
4717 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4718 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4719 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4720 2483968 }
4721
4722 9703 palpos-=palstep;
4723
4724
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4725 {
4726 9703 hw_palette = &wavepal;
4727 9703 update_hw_pal = true;
4728 9703 }
4729 else
4730 {
4731 hw_palette = &RAMpal;
4732 update_hw_pal = true;
4733 }
4734
4735
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4736 {
4737
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4738 {
4739 417306624 ofs=0;
4740
4741
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4742 {
4743 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4744 104337152 }
4745
4746 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4747 417306624 }
4748 1630104 }
4749
4750 9703 advanceframe(true);
4751
4752
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4753 1 break;
4754 9702 }
4755
4756 232 destroy_bitmap(wavebuf);
4757
4758 232 hw_palette = &RAMpal;
4759 232 update_hw_pal = true;
4760 232 }
4761
4762 4342 void blackscr(int32_t fcnt,bool showsubscr)
4763 {
4764 4342 reset_pal_cycling();
4765 4342 script_drawing_commands.Clear();
4766
4767 4342 FFCore.warpScriptCheck();
4768 4342 bool showtime = game->should_show_time();
4769
2/2
✓ Branch 0 taken 4335 times.
✓ Branch 1 taken 129817 times.
134152 while(fcnt>0)
4770 {
4771 129817 clear_bitmap(framebuf);
4772
4773
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70507 times.
129817 if(showsubscr)
4774 {
4775 70507 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4776
3/4
✓ Branch 0 taken 70507 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1290 times.
✓ Branch 3 taken 69217 times.
70507 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4777 {
4778 1290 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4779 1290 }
4780 70507 }
4781
4782 129817 advanceframe(true);
4783
4784
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129810 times.
129817 if(Quit)
4785 7 break;
4786
4787 129810 --fcnt;
4788 }
4789 4342 }
4790
4791 2729 void openscreen(int32_t shape)
4792 {
4793 2729 update_viewport();
4794 2729 is_opening_screen = true;
4795 2729 reset_pal_cycling();
4796 2729 black_opening_count=0;
4797
4798
3/4
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 2199 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 530 times.
2729 if(COOLSCROLL || shape>-1)
4799 {
4800 2199 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4801 2199 return;
4802 }
4803 else
4804 {
4805 530 Hero.setDontDraw(true);
4806 530 show_subscreen_dmap_dots=false;
4807 530 show_subscreen_numbers=false;
4808 530 show_subscreen_life=false;
4809 }
4810
4811 530 int32_t x=128;
4812
4813 530 FFCore.warpScriptCheck();
4814
2/2
✓ Branch 0 taken 530 times.
✓ Branch 1 taken 42400 times.
42930 for(int32_t i=0; i<80; i++)
4815 {
4816 42400 draw_screen();
4817 42400 x=128-(((i*128/80)/8)*8);
4818
4819
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(x>0)
4820 {
4821 42400 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4822 42400 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4823 42400 }
4824
4825 42400 advanceframe(true);
4826
4827
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42400 times.
42400 if(Quit)
4828 {
4829 break;
4830 }
4831 42400 }
4832
4833 530 Hero.setDontDraw(false);
4834 530 show_subscreen_items=true;
4835 530 show_subscreen_dmap_dots=true;
4836 530 show_subscreen_numbers=true;
4837 530 show_subscreen_life=true;
4838 2729 }
4839
4840 14 void closescreen(int32_t shape)
4841 {
4842 14 is_opening_screen = false;
4843 14 reset_pal_cycling();
4844 14 black_opening_count=0;
4845
4846
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4847 {
4848 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4849 14 return;
4850 }
4851 else
4852 {
4853 Hero.setDontDraw(true);
4854 show_subscreen_dmap_dots=false;
4855 show_subscreen_numbers=false;
4856 // show_subscreen_items=false;
4857 show_subscreen_life=false;
4858 }
4859
4860 int32_t x=128;
4861
4862 FFCore.warpScriptCheck();
4863 for(int32_t i=79; i>=0; --i)
4864 {
4865 draw_screen();
4866 x=128-(((i*128/80)/8)*8);
4867
4868 if(x>0)
4869 {
4870 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4871 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4872 }
4873
4874 advanceframe(true);
4875
4876 if(Quit)
4877 {
4878 break;
4879 }
4880 }
4881
4882 Hero.setDontDraw(false);
4883 show_subscreen_items=true;
4884 show_subscreen_dmap_dots=true;
4885 14 }
4886
4887 324 int32_t TriforceCount()
4888 {
4889 324 int32_t c=0;
4890
4891
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4892
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&liTRIFORCE)
4893 2108 ++c;
4894
4895 324 return c;
4896 }
4897
4898 int32_t onCustomGame()
4899 {
4900 auto save = get_unset_save_slot();
4901 if (!save)
4902 return D_CLOSE;
4903
4904 if (prompt_for_quest_path(save->header->qstpath))
4905 {
4906 save->header->qstpath = qstpath;
4907 return D_O_K;
4908 }
4909
4910 return D_CLOSE;
4911 }
4912
4913 int32_t onContinue()
4914 {
4915 return D_CLOSE;
4916 }
4917
4918 int32_t onThrottleFPS()
4919 {
4920 Throttlefps = !Throttlefps;
4921 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4922 return D_O_K;
4923 }
4924
4925 int32_t onWinPosSave()
4926 {
4927 SaveWinPos = !SaveWinPos;
4928 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4929 return D_O_K;
4930 }
4931 int32_t onIntegerScaling()
4932 {
4933 scaleForceInteger = !scaleForceInteger;
4934 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4935 return D_O_K;
4936 }
4937 int32_t onStretchGame()
4938 {
4939 stretchGame = !stretchGame;
4940 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4941 return D_O_K;
4942 }
4943
4944 int32_t onClickToFreeze()
4945 {
4946 ClickToFreeze = !ClickToFreeze;
4947 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4948 return D_O_K;
4949 }
4950
4951 int32_t OnSaveZCConfig()
4952 {
4953 if(jwin_alert3(
4954 "Save Configuration",
4955 "Are you sure that you wish to save your present configuration settings?",
4956 "This will overwrite your prior settings!",
4957 NULL,
4958 "&Yes",
4959 "&No",
4960 NULL,
4961 'y',
4962 'n',
4963 0,
4964 get_zc_font(font_lfont)) == 1)
4965 {
4966 save_game_configs();
4967 return D_O_K;
4968 }
4969 else return D_O_K;
4970 }
4971
4972 int32_t OnnClearQuestDir()
4973 {
4974 auto current_path = fs::current_path() / "quests";
4975 if(jwin_alert3(
4976 "Clear Current Directory Cache",
4977 "Are you sure that you wish to reset where ZC Player looks for quests?",
4978 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4979 NULL,
4980 "&Yes",
4981 "&No",
4982 NULL,
4983 'y',
4984 'n',
4985 0,
4986 get_zc_font(font_lfont)) == 1)
4987 {
4988 zc_set_config("zeldadx","quest_dir","quests");
4989 flush_config_file();
4990 strcpy(qstdir,"quests");
4991 #ifdef __EMSCRIPTEN__
4992 em_sync_fs();
4993 #endif
4994 return D_O_K;
4995 }
4996 else return D_O_K;
4997 }
4998
4999 int32_t onConsole()
5000 {
5001 if ( !console_enabled )
5002 {
5003 AlertDialog("ZC Console",
5004 "Open the ZC Console?"
5005 "\nThis will display any messages logged by scripts,"
5006 " including errors.",
5007 [&](bool ret,bool)
5008 {
5009 if(ret)
5010 {
5011 FFCore.ZScriptConsole(true);
5012 }
5013 }).show();
5014 return D_O_K;
5015 }
5016 else
5017 {
5018 FFCore.ZScriptConsole(false);
5019 return D_O_K;
5020 }
5021 }
5022
5023 int32_t onClrConsoleOnReload()
5024 {
5025 clearConsoleOnReload = !clearConsoleOnReload;
5026 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5027 return D_O_K;
5028 }
5029 int32_t onClrConsoleOnLoad()
5030 {
5031 clearConsoleOnLoad = !clearConsoleOnLoad;
5032 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5033 return D_O_K;
5034 }
5035
5036
5037 int32_t onFrameSkip()
5038 {
5039 FrameSkip = !FrameSkip;
5040 return D_O_K;
5041 }
5042
5043 int32_t onSaveDragResize()
5044 {
5045 SaveDragResize = !SaveDragResize;
5046 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5047 return D_O_K;
5048 }
5049
5050 int32_t onDragAspect()
5051 {
5052 DragAspect = !DragAspect;
5053 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5054 return D_O_K;
5055 }
5056
5057 int32_t onTransLayers()
5058 {
5059 TransLayers = !TransLayers;
5060 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5061 return D_O_K;
5062 }
5063
5064 int32_t onNESquit()
5065 {
5066 NESquit = !NESquit;
5067 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5068 return D_O_K;
5069 }
5070
5071 int32_t onVolKeys()
5072 {
5073 volkeys = !volkeys;
5074 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5075 return D_O_K;
5076 }
5077
5078 int32_t onShowFPS()
5079 {
5080 ShowFPS = !ShowFPS;
5081 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5082 return D_O_K;
5083 }
5084
5085 int32_t onShowTime()
5086 {
5087 ShowGameTime = !ShowGameTime;
5088 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5089 return D_O_K;
5090 }
5091
5092 2182569418 bool is_Fkey(int32_t k)
5093 {
5094
2/2
✓ Branch 0 taken 221956212 times.
✓ Branch 1 taken 1960613206 times.
2182569418 switch(k)
5095 {
5096 case KEY_F1:
5097 case KEY_F2:
5098 case KEY_F3:
5099 case KEY_F4:
5100 case KEY_F5:
5101 case KEY_F6:
5102 case KEY_F7:
5103 case KEY_F8:
5104 case KEY_F9:
5105 case KEY_F10:
5106 case KEY_F11:
5107 case KEY_F12:
5108 221956212 return true;
5109 }
5110
5111 1960613206 return false;
5112 2182569418 }
5113
5114 void kb_getkey(DIALOG *d);
5115
5116 //Used by all keyboard key settings dialogues.
5117 void kb_clearjoystick(DIALOG *d)
5118 {
5119 d->flags|=D_SELECTED;
5120
5121 jwin_button_proc(MSG_DRAW,d,0);
5122 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5123 // text_mode(vc(11));
5124 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5125 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5126
5127 update_hw_screen();
5128
5129 clear_keybuf();
5130 int32_t k = next_press_key();
5131 clear_keybuf();
5132
5133 //shnarf
5134 //47=f1
5135 //59=esc
5136 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5137 // *((int32_t*)d->dp3) = k;
5138 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5139
5140
5141 d->flags&=~D_SELECTED;
5142 }
5143
5144 //Clears key to 0.
5145 //Used by all keyboard key settings dialogues.
5146 void kb_clearkey(DIALOG *d);
5147
5148 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5149 {
5150 switch(msg)
5151 {
5152 case MSG_KEY:
5153 case MSG_CLICK:
5154
5155 kb_clearjoystick(d);
5156
5157 while(gui_mouse_b())
5158 {
5159 clear_keybuf();
5160 rest(1);
5161 }
5162
5163 return D_REDRAW;
5164 }
5165
5166 return jwin_button_proc(msg,d,c);
5167 }
5168
5169 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5170 //Only used in keyboard settings dialogues to clear keys.
5171 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5172
5173 int32_t j_getbtn(DIALOG *d)
5174 {
5175 d->flags|=D_SELECTED;
5176 jwin_button_proc(MSG_DRAW,d,0);
5177 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5178 // text_mode(vc(11));
5179 int32_t y = screen->h/2 - 12;
5180 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5181 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5182 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5183
5184 update_hw_screen();
5185
5186 int32_t b = next_joy_input(true);
5187 if (b == -2)
5188 return D_CLOSE;
5189
5190 if(b>=0)
5191 *((int32_t*)d->dp3) = b;
5192
5193 d->flags&=~D_SELECTED;
5194
5195 return D_O_K;
5196 }
5197
5198 void j_getstick(DIALOG *d)
5199 {
5200 d->flags|=D_SELECTED;
5201 jwin_button_proc(MSG_DRAW,d,0);
5202 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5203 // text_mode(vc(11));
5204 int32_t y = screen->h/2 - 12;
5205 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5206 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5207 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5208
5209 update_hw_screen();
5210
5211 int32_t b = next_joy_input(false);
5212
5213 if(b>=0)
5214 *((int32_t*)d->dp3) = b;
5215
5216 d->flags&=~D_SELECTED;
5217 }
5218
5219 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5220 {
5221 switch(msg)
5222 {
5223 case MSG_KEY:
5224 case MSG_CLICK:
5225
5226 int ret = j_getbtn(d);
5227 if (ret != D_O_K)
5228 return ret;
5229
5230 while(gui_mouse_b()) {
5231 rest(1);
5232 clear_keybuf();
5233 }
5234
5235 return D_REDRAW;
5236 }
5237
5238 return jwin_button_proc(msg,d,c);
5239 }
5240
5241 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5242 {
5243 switch(msg)
5244 {
5245 case MSG_KEY:
5246 case MSG_CLICK:
5247
5248 j_getstick(d);
5249
5250 while(gui_mouse_b()) {
5251 rest(1);
5252 clear_keybuf();
5253 }
5254
5255 return D_REDRAW;
5256 }
5257
5258 return jwin_button_proc(msg,d,c);
5259 }
5260
5261 //shnarf
5262 extern const char *key_str[];
5263 std::string get_keystr(int key);
5264
5265 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5266
5267 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5268 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5269 str_primary_stick[80], str_secondary_stick[80];
5270
5271 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5272 {
5273 //these are here to bypass compiler warnings about unused arguments
5274 c=c;
5275
5276 if (d->w == 1)
5277 {
5278 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5279 {
5280 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5281 return D_CLOSE;
5282 }
5283 }
5284
5285 if(msg==MSG_DRAW)
5286 {
5287 switch(d->w)
5288 {
5289 case 0:
5290 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5291 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5292 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5293 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5294 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5295 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5296 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5297 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5298 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5299 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5300 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5301 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5302 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5303 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5304 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5305 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5306 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5307 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5308 break;
5309
5310 case 1:
5311 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5312 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5313 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5314 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5315 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5316 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5317 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5318 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5319 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5320 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5321 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5322 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5323 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5324 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5325 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5326 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5327 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5328 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5329 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5330 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5331 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5332 break;
5333
5334 case 2:
5335 sprintf(str_a," %3d",midi_volume);
5336 sprintf(str_l," %3d",emusic_volume);
5337 sprintf(str_r," %3d",sfx_volume);
5338 strcpy(str_s,pan_str[pan_style]);
5339 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5340 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5341 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5342 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5343 break;
5344 }
5345 }
5346
5347 return D_O_K;
5348 }
5349
5350 int32_t set_vol(void *dp3, int32_t d2)
5351 {
5352 switch(((int32_t*)dp3)[0])
5353 {
5354 case 0:
5355 midi_volume = zc_min(d2<<3,255);
5356 break;
5357
5358 case 1:
5359 digi_volume = zc_min(d2<<3,255);
5360 break;
5361
5362 case 2:
5363 emusic_volume = zc_min(d2<<3,255);
5364 break;
5365
5366 case 3:
5367 sfx_volume = zc_min(d2<<3,255);
5368 break;
5369 }
5370
5371 // text_mode(vc(11));
5372 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5373 return D_O_K;
5374 }
5375
5376 int32_t set_pan(void *dp3, int32_t d2)
5377 {
5378 pan_style = vbound(d2,0,3);
5379 // text_mode(vc(11));
5380 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5381 return D_O_K;
5382 }
5383
5384 static int32_t gamepad_joys_list[] =
5385 {
5386 61,
5387 -1
5388 };
5389
5390 static int32_t gamepad_btn_list[] =
5391 {
5392 6,
5393 7,8,9,10,11,12,13,14,15,16,17,
5394 18,19,20,21,22,23,24,25,26,27,28,
5395 29,30,31,32,33,34,35,36,37,38,39,
5396 -1
5397 };
5398
5399 static int32_t gamepad_dirs_list[] =
5400 {
5401 40,41,42,43,
5402 44,45,46,47,
5403 48,49,50,51,
5404 52,53,54,55,
5405 56,57,58,59,
5406 60,
5407 -1
5408 };
5409
5410 static TABPANEL gamepad_tabs[] =
5411 {
5412 // (text)
5413 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5414 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5415 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5416 { NULL, 0, NULL, 0, NULL }
5417 };
5418
5419 const char *joy_list(int32_t index, int32_t *list_size)
5420 {
5421 if (index == -1)
5422 {
5423 *list_size = al_get_num_joysticks();
5424 return NULL;
5425 }
5426
5427 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5428 if (!joy)
5429 {
5430 return "?";
5431 }
5432
5433 return al_get_joystick_name(joy);
5434 }
5435
5436 399 static ListData joy__list(joy_list, &font);
5437
5438 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5439 {
5440 int32_t d2 = d->d2;
5441 int32_t ret = jwin_droplist_proc(msg,d,c);
5442
5443 if(d2!=d->d2)
5444 {
5445 joystick_index = d->d2;
5446 ret |= D_REDRAW_ALL;
5447 }
5448
5449 return ret;
5450 }
5451
5452 static DIALOG gamepad_dlg[] =
5453 {
5454 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5455 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5456 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5457 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5458 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5459 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5460 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5461 // 6
5462 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5463 // 7
5464 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5465 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5466 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5467 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5468 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5469 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5470 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5471 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5472 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5473 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5474 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5475 // 18
5476 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5477 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5478 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5479 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5480 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5481 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5482 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5483 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5484 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5485 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5486 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5487 // 29
5488 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5489 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5490 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5491 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5492 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5493 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5494 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5495 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5496 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5497 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5498 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5499 // 40
5500 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5501 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5502 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5503 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5504 // 44
5505 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5506 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5507 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5508 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5509 // 48
5510 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5511 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5512 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5513 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5514 // 52
5515 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5516 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5517 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5518 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5519 // 56
5520 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5521 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5522 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5523 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5524 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5525
5526 // 61
5527 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5528
5529 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5530 };
5531
5532 static int32_t keyboard_keys_list[] =
5533 {
5534 6,7,8,9,10,
5535 11,12,13,14,15,16,17,18,19,20,
5536 21,22,23,24,25,26,27,28,29,30,
5537 31,32,33,34,35,36,37,38,39,40,
5538 -1
5539 };
5540
5541 static int32_t keyboard_dirs_list[] =
5542 {
5543 41,42,43,44,
5544 45,46,47,48,
5545 49,50,51,52,
5546 53,54,55,56,
5547 -1
5548 };
5549
5550 static int32_t keyboard_mods_list[] =
5551 {
5552 57,58,59,60,
5553 61,62,63,64,
5554 65,66,67,68,
5555 69,70,71,72,
5556 -1
5557 };
5558
5559 static TABPANEL keyboard_control_tabs[] =
5560 {
5561 // (text)
5562 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5563 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5564 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5565 { NULL, 0, NULL, 0, NULL }
5566 };
5567
5568 static DIALOG keyboard_control_dlg[] =
5569 {
5570 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5571 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5572 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5573 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5574 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5575 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5576 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5577 // Keys
5578 // 6
5579 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5580 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5581 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5582 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5583 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5584 // 11
5585 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5586 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5587 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5588 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5589 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5590 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5591 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5592 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5593 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5594 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5595 // 21
5596 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5597 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5598 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5599 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5600 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5601 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5602 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5603 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5604 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5605 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5606 // 31
5607 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5608 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5609 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5610 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5611 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5612 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5613 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5614 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5615 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5616 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5617 // Dirs
5618 // 41
5619 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5620 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5621 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5622 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5623 // 45
5624 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5625 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5626 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5627 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5628 // 49
5629 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5630 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5631 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5632 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5633 // 53
5634 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5635 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5636 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5637 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5638 // Mods
5639 // 57
5640 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5641 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5642 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5643 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5644 // 61
5645 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5646 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5647 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5648 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5649 // 65
5650 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5651 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5652 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5653 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5654 // 69
5655 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5656 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5657 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5658 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5659 // 73
5660 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5661 };
5662
5663 int32_t midi_dp[3] = {0,0,0};
5664 int32_t emus_dp[3] = {2,0,0};
5665 int32_t sfx_dp[3] = {3,0,0};
5666 int32_t pan_dp[3] = {0,0,0};
5667
5668 static DIALOG sound_dlg[] =
5669 {
5670 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5671 399 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5672 399 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5673 399 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5674 399 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5675 399 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5676 399 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5677 399 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5678 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5679 399 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5680 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5681 // 10
5682 399 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5683 399 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5684 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5686 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5687 399 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5688 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5689 399 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5690 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5691 399 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5692 //20
5693 399 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5694 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5696 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5697 399 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5698 399 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5699 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5700 399 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5701 399 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5702 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5703 //30
5704 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5705 399 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5706 399 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 };
5708
5709 char zc_builddate[80];
5710 char zc_aboutstr[80];
5711
5712 static DIALOG about_dlg[] =
5713 {
5714 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5715 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5716 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5717 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5718 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5719 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5720 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5721 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5722 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5723 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5724 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5725 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5726 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5727 };
5728
5729
5730 static DIALOG quest_dlg[] =
5731 {
5732 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5733 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5734 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5735 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5736 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5737 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5738 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5739 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5740 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5741 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5742 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5743 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5744 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5745 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5746 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5747 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5748 };
5749
5750 static DIALOG triforce_dlg[] =
5751 {
5752 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5753 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5754 // 1
5755 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5756 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5757 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5758 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5759 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5760 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5761 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5762 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5763 // 9
5764 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5765 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5766 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5767 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5768 };
5769
5770 int32_t onToggleRecordingNewSaves()
5771 {
5772 if (zc_get_config("zeldadx", "replay_new_saves", false))
5773 {
5774 zc_set_config("zeldadx", "replay_new_saves", false);
5775 }
5776 else
5777 {
5778 zc_set_config("zeldadx", "replay_new_saves", true);
5779 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5780 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5781 }
5782 return D_O_K;
5783 }
5784
5785 #ifdef HAS_CURL
5786 int32_t onToggleAutoUploadReplays()
5787 {
5788 if (zc_get_config("zeldadx", "replay_upload", false))
5789 {
5790 zc_set_config("zeldadx", "replay_upload", false);
5791 }
5792 else
5793 {
5794 zc_set_config("zeldadx", "replay_upload", true);
5795 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5796 " preventing bugs and simplifying bug reports.",
5797 "Upload will happen no more than once a week when closing ZC",
5798 "OK",NULL,13,27,get_zc_font(font_lfont));
5799
5800 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5801 onToggleRecordingNewSaves();
5802 }
5803 return D_O_K;
5804 }
5805
5806 int32_t onUploadReplays()
5807 {
5808 if(jwin_alert3(
5809 "Upload replays",
5810 "Upload your replays now to assist in development?",
5811 NULL,
5812 NULL,
5813 "&Yes",
5814 "&No",
5815 NULL,
5816 'y',
5817 'n',
5818 0,
5819 get_zc_font(font_lfont)) == 1)
5820 {
5821 int num_uploaded = replay_upload();
5822 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5823 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5824 }
5825 return D_O_K;
5826 }
5827
5828 int32_t onClearUploadCache()
5829 {
5830 if(jwin_alert3(
5831 "Upload replays",
5832 "Clear the upload cache?",
5833 "This simply deletes replays/state.json. There's no harm in doing this, but",
5834 "likely is not necessary.",
5835 "&Yes",
5836 "&No",
5837 NULL,
5838 'y',
5839 'n',
5840 0,
5841 get_zc_font(font_lfont)) == 1)
5842 {
5843 replay_upload_clear_cache();
5844 }
5845 return D_O_K;
5846 }
5847 #endif
5848
5849 int32_t onToggleSnapshotAllFrames()
5850 {
5851 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5852 return D_O_K;
5853 }
5854
5855 int32_t onStopReplayOrRecord()
5856 {
5857 if (replay_is_replaying())
5858 {
5859 replay_quit();
5860 }
5861 else if (replay_get_mode() == ReplayMode::Record)
5862 {
5863 if (!replay_get_meta_bool("test_mode"))
5864 {
5865 jwin_alert("Recording", "You cannot stop recording a save file.",
5866 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5867 return D_CLOSE;
5868 }
5869
5870 if (jwin_alert("Stop Recording",
5871 "Save replay to disk and stop recording?",
5872 "This will stop the recording.",
5873 NULL,
5874 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5875 return D_CLOSE;
5876
5877 replay_save();
5878 replay_stop();
5879 }
5880 return D_O_K;
5881 }
5882
5883 static int32_t handle_on_load_replay(ReplayMode mode)
5884 {
5885 bool ctrl = CHECK_CTRL_CMD;
5886 if (Playing)
5887 {
5888 if (jwin_alert("Replay - Warning!",
5889 "Loading a replay will exit the current game.",
5890 "All unsaved progress will be lost.",
5891 "Do you wish to continue?",
5892 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5893 return D_CLOSE;
5894 }
5895
5896 std::string mode_string = replay_mode_to_string(mode);
5897 mode_string[0] = std::toupper(mode_string[0]);
5898
5899 std::string line_1 = "Select a replay file to play back.";
5900 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5901 std::string line_3 = "You can stop the replay and take over manually any time.";
5902 if (mode == ReplayMode::Update)
5903 {
5904 line_1 = "Select a replay file to update.";
5905 line_2 = "WARNING: be sure to back up the zplay file";
5906 line_3 = "and verify that the updated replay works as expected!";
5907 }
5908
5909 if (jwin_alert(mode_string.c_str(),
5910 line_1.c_str(),
5911 line_2.c_str(),
5912 line_3.c_str(),
5913 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5914 {
5915 std::string replay_path = "replays/";
5916 if(ctrl && devpwd())
5917 replay_path = "../../tests/replays/";
5918 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5919 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5920 replay_path = *result;
5921 else
5922 return D_CLOSE;
5923
5924 replay_quit();
5925 load_replay_file_deferred(mode, replay_path);
5926 Quit = qRESET;
5927 return D_CLOSE;
5928 }
5929 return D_O_K;
5930 }
5931
5932 int32_t onLoadReplay()
5933 {
5934 return handle_on_load_replay(ReplayMode::Replay);
5935 }
5936
5937 int32_t onLoadReplayAssert()
5938 {
5939 return handle_on_load_replay(ReplayMode::Assert);
5940 }
5941
5942 int32_t onLoadReplayUpdate()
5943 {
5944 return handle_on_load_replay(ReplayMode::Update);
5945 }
5946
5947 int32_t onSaveReplay()
5948 {
5949 if (replay_get_mode() == ReplayMode::Record)
5950 {
5951 if (!replay_get_meta_bool("test_mode"))
5952 {
5953 if (jwin_alert("Save Replay",
5954 "This will save a copy of the replay up to this point.",
5955 "The official replay file will be untouched.",
5956 "Do you wish to continue?",
5957 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5958 {
5959 return D_CLOSE;
5960 }
5961
5962 std::string replay_path = replay_get_replay_path().string();
5963 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5964 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5965 replay_path = *result;
5966 else
5967 return D_CLOSE;
5968
5969 if (fileexists(replay_path.c_str()))
5970 {
5971 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5972 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5973 return D_CLOSE;
5974 }
5975
5976 replay_save(replay_path);
5977 }
5978 else
5979 {
5980 replay_save();
5981 }
5982 }
5983 return D_O_K;
5984 }
5985
5986 enum
5987 {
5988 MENUID_REPLAY_RECORDNEW,
5989 MENUID_REPLAY_STOP,
5990 MENUID_REPLAY_SAVE,
5991 MENUID_REPLAY_SNAP_ALL,
5992 MENUID_REPLAY_AUTOUPLOAD,
5993 MENUID_REPLAY_UPLOAD,
5994 MENUID_REPLAY_CLEARUPLOADCACHE,
5995 };
5996
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu replay_menu
5997 5187 {
5998
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
5999
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
6000
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6001
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Load replay", onLoadReplay },
6002
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Load replay (assert)", onLoadReplayAssert },
6003
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Load replay (update)", onLoadReplayUpdate },
6004
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6005
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6006 #ifdef HAS_CURL
6007
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
6008
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6009
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6010
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6011 #endif
6012 };
6013
6014 static DIALOG credits_dlg[] =
6015 {
6016 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6017 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6018 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6019 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6020 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6021 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6022 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6023 };
6024
6025 399 static ListData dmap_list(dmaplist, &font);
6026
6027 static DIALOG goto_dlg[] =
6028 {
6029 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6030 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6031 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6032 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6033 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6034 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6035 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6036 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6037 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6038 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6039 };
6040
6041 int32_t onGoTo()
6042 {
6043 bool music = false;
6044 music = music;
6045 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6046
6047 goto_dlg[0].dp2=get_zc_font(font_lfont);
6048 goto_dlg[4].d2=cheat_goto_dmap;
6049 goto_dlg[6].dp=cheat_goto_screen_str;
6050
6051 clear_keybuf();
6052
6053 large_dialog(goto_dlg);
6054
6055 if(do_zqdialog(goto_dlg,4)==1)
6056 {
6057 int dmap = goto_dlg[4].d2;
6058 int screen = zc_xtoi(cheat_goto_screen_str);
6059 int adjusted_screen = screen + DMaps[dmap].xoff;
6060 if (adjusted_screen < 0 || adjusted_screen >= 128)
6061 {
6062 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6063 }
6064 else
6065 {
6066 cheats_enqueue(Cheat::GoTo, dmap, screen);
6067 }
6068 };
6069
6070 return D_O_K;
6071 }
6072
6073 int32_t onGoToComplete()
6074 {
6075 if(!Playing)
6076 {
6077 return D_O_K;
6078 }
6079
6080 enter_sys_pal();
6081 music_pause();
6082 pause_all_sfx();
6083 onGoTo();
6084 eat_buttons();
6085
6086 zc_readrawkey(KEY_ESC);
6087
6088 exit_sys_pal();
6089 music_resume();
6090 resume_all_sfx();
6091 return D_O_K;
6092 }
6093
6094 int32_t onCredits()
6095 {
6096 return D_O_K;
6097 }
6098
6099 const char *midilist(int32_t index, int32_t *list_size)
6100 {
6101 if(index<0)
6102 {
6103 *list_size=0;
6104
6105 for(int32_t i=0; i<MAXMIDIS; i++)
6106 if(tunes[i].data)
6107 ++(*list_size);
6108
6109 return NULL;
6110 }
6111
6112 int32_t i=0,m=0;
6113
6114 while(m<=index && i<=MAXMIDIS)
6115 {
6116 if(tunes[i].data)
6117 ++m;
6118
6119 ++i;
6120 }
6121
6122 --i;
6123
6124 if(i==MAXMIDIS && m<index)
6125 return "(null)";
6126
6127 return tunes[i].title;
6128 }
6129
6130 /* ------- MIDI info stuff -------- */
6131
6132 char *text;
6133 midi_info *zmi;
6134 bool dialog_running;
6135 bool listening;
6136
6137 void get_info(int32_t index);
6138
6139 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6140 {
6141 int32_t d2 = d->d2;
6142 int32_t ret = jwin_droplist_proc(msg,d,c);
6143
6144 if(d2!=d->d2)
6145 {
6146 get_info(d->d2);
6147 }
6148
6149 return ret;
6150 }
6151
6152 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6153 {
6154 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6155
6156 int32_t ret = jwin_button_proc(msg,d,c);
6157
6158 if(ret == D_CLOSE)
6159 {
6160 // get current midi index
6161 int32_t index = (d+(d->d1))->d2;
6162 int32_t i=0, m=0;
6163
6164 while(m<=index && i<=MAXMIDIS)
6165 {
6166 if(tunes[i].data)
6167 ++m;
6168
6169 ++i;
6170 }
6171
6172 --i;
6173 jukebox(i);
6174 listening = true;
6175 ret = D_O_K;
6176 }
6177
6178 return ret;
6179 }
6180
6181 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6182 {
6183 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6184
6185 int32_t ret = jwin_button_proc(msg,d,c);
6186
6187 if(ret == D_CLOSE)
6188 {
6189 // get current midi index
6190 int32_t index = (d+(d->d1))->d2;
6191 int32_t i=0, m=0;
6192
6193 while(m<=index && i<=MAXMIDIS)
6194 {
6195 if(tunes[i].data)
6196 ++m;
6197
6198 ++i;
6199 }
6200
6201 --i;
6202
6203 char title[40] = "Save MIDI: ";
6204 static EXT_LIST list[] =
6205 {
6206 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6207 { NULL, NULL }
6208 };
6209
6210 strcpy(title+11, tunes[i].title);
6211 title[39] = '\0';
6212
6213 std::string fname;
6214 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6215 fname = *result;
6216 else
6217 goto done;
6218
6219 if(exists(fname.c_str()))
6220 {
6221 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6222 goto done;
6223 }
6224
6225 // save midi i
6226
6227 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6228 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6229
6230 done:
6231 chop_path(fname.data());
6232 ret = D_REDRAW;
6233 }
6234
6235 return ret;
6236 }
6237
6238 399 static ListData midi_list(midilist, &font);
6239
6240 static DIALOG midi_dlg[] =
6241 {
6242 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6243 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6244 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6245 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6246 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6247 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6248 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6249 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6250 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6251 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6252 };
6253
6254 void get_info(int32_t index)
6255 {
6256 int32_t i=0, m=0;
6257
6258 while(m<=index && i<=MAXMIDIS)
6259 {
6260 if(tunes[i].data)
6261 ++m;
6262
6263 ++i;
6264 }
6265
6266 --i;
6267
6268 if(i==MAXMIDIS && m<index)
6269 strcpy(text,"(null)");
6270 else
6271 {
6272 get_midi_info(tunes[i].data,zmi);
6273 get_midi_text(tunes[i].data,zmi,text);
6274 }
6275
6276 midi_dlg[0].dp2=get_zc_font(font_lfont);
6277 midi_dlg[3].dp = text;
6278 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6279 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6280
6281 if(dialog_running)
6282 {
6283 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6284 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6285 }
6286 }
6287
6288 int32_t onMIDICredits()
6289 {
6290 text = (char*)malloc(4096);
6291 zmi = (midi_info*)malloc(sizeof(midi_info));
6292
6293 if(!text || !zmi)
6294 {
6295 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6296 return D_O_K;
6297 }
6298
6299 bool do_pause_midi = midi_pos >= 0 && currmidi;
6300 auto restore_midi = currmidi;
6301 if(do_pause_midi)
6302 {
6303 paused_midi_pos = midi_pos;
6304 stop_midi();
6305 midi_suspended = midissuspHALTED;
6306 }
6307
6308 midi_dlg[0].dp2=get_zc_font(font_lfont);
6309 midi_dlg[2].d1 = 0;
6310 midi_dlg[2].d2 = 0;
6311 midi_dlg[4].flags = D_EXIT;
6312 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6313
6314 listening = false;
6315 dialog_running=false;
6316 get_info(0);
6317
6318 dialog_running=true;
6319
6320 large_dialog(midi_dlg);
6321
6322 do_zqdialog(midi_dlg,0);
6323 dialog_running=false;
6324
6325 if(listening)
6326 music_stop();
6327
6328 if(do_pause_midi)
6329 {
6330 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6331 midi_suspended = midissuspRESUME;
6332 currmidi = restore_midi;
6333 midi_pos = paused_midi_pos;
6334 }
6335
6336 if(text) free(text);
6337 if(zmi) free(zmi);
6338 return D_O_K;
6339 }
6340
6341 int32_t onAbout()
6342 {
6343 char buf1[80]={0};
6344 std::ostringstream oss;
6345 sprintf(buf1,"ZQuest Classic Player");
6346 oss << buf1 << '\n';
6347 sprintf(buf1,"Version: %s", getVersionString());
6348 oss << buf1 << '\n';
6349 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6350 oss << buf1 << '\n';
6351
6352 InfoDialog("About ZC", oss.str()).show();
6353 return D_O_K;
6354 }
6355
6356 int32_t onQuest()
6357 {
6358 char fname[100];
6359 strcpy(fname, get_filename(qstpath));
6360 quest_dlg[0].dp2=get_zc_font(font_lfont);
6361 quest_dlg[1].dp = fname;
6362
6363 if(QHeader.quest_number==0)
6364 sprintf(str_a,"Custom");
6365 else
6366 sprintf(str_a,"%d",QHeader.quest_number);
6367
6368 sprintf(str_s,"%s",QHeader.getVerStr());
6369
6370 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6371 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6372
6373 large_dialog(quest_dlg);
6374
6375 do_zqdialog(quest_dlg, 0);
6376 return D_O_K;
6377 }
6378
6379 void call_vidmode_dlg();
6380 int32_t onVidMode()
6381 {
6382 call_vidmode_dlg();
6383 return D_O_K;
6384 }
6385
6386 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6387 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6388 //Added an extra statement, so that if the key is cleared to 0, the cleared
6389 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6390
6391 void load_ukeys(int32_t* arr)
6392 {
6393 arr[ukey_a] = Akey;
6394 arr[ukey_b] = Bkey;
6395 arr[ukey_s] = Skey;
6396 arr[ukey_l] = Lkey;
6397 arr[ukey_r] = Rkey;
6398 arr[ukey_p] = Pkey;
6399 arr[ukey_ex1] = Exkey1;
6400 arr[ukey_ex2] = Exkey2;
6401 arr[ukey_ex3] = Exkey3;
6402 arr[ukey_ex4] = Exkey4;
6403 arr[ukey_du] = DUkey;
6404 arr[ukey_dd] = DDkey;
6405 arr[ukey_dl] = DLkey;
6406 arr[ukey_dr] = DRkey;
6407 arr[ukey_mod1a] = cheat_modifier_keys[0];
6408 arr[ukey_mod1b] = cheat_modifier_keys[1];
6409 arr[ukey_mod2a] = cheat_modifier_keys[2];
6410 arr[ukey_mod2b] = cheat_modifier_keys[3];
6411 };
6412
6413 static const char* ukey_names[] = {
6414 "A", "B", "Start", "L", "R", "Map",
6415 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6416 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6417 "Cheat Mod R1", "Cheat Mod R2",
6418 };
6419 std::string get_ukey_name(int32_t k)
6420 {
6421 if (k < num_ukey) return ukey_names[k];
6422 return "";
6423 }
6424
6425 int32_t onKeyboard()
6426 {
6427 int32_t a = Akey;
6428 int32_t b = Bkey;
6429 int32_t s = Skey;
6430 int32_t l = Lkey;
6431 int32_t r = Rkey;
6432 int32_t p = Pkey;
6433 int32_t ex1 = Exkey1;
6434 int32_t ex2 = Exkey2;
6435 int32_t ex3 = Exkey3;
6436 int32_t ex4 = Exkey4;
6437 int32_t du = DUkey;
6438 int32_t dd = DDkey;
6439 int32_t dl = DLkey;
6440 int32_t dr = DRkey;
6441 int32_t mod1a = cheat_modifier_keys[0];
6442 int32_t mod1b = cheat_modifier_keys[1];
6443 int32_t mod2a = cheat_modifier_keys[2];
6444 int32_t mod2b = cheat_modifier_keys[3];
6445 bool done=false;
6446 int32_t ret;
6447
6448 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6449
6450 large_dialog(keyboard_control_dlg);
6451
6452 while(!done)
6453 {
6454 ret = do_zqdialog(keyboard_control_dlg,3);
6455
6456 if(ret==3) // OK
6457 {
6458 int32_t ukeys[num_ukey];
6459 load_ukeys(ukeys);
6460 std::vector<std::string> uniqueError;
6461 for(int32_t q = 0; q < num_ukey; ++q)
6462 {
6463 for(int32_t p = q+1; p < num_ukey; ++p)
6464 {
6465 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6466 {
6467 char buf[64];
6468 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6469 std::string str(buf);
6470 uniqueError.push_back(str);
6471 }
6472 }
6473 }
6474 if(uniqueError.size() == 0)
6475 {
6476 done = true;
6477 save_control_configs(true);
6478 }
6479 else
6480 {
6481 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6482 box_out("Cannot have duplicate keybinds!"); box_eol();
6483 for(std::vector<std::string>::iterator it = uniqueError.begin();
6484 it != uniqueError.end(); ++it)
6485 {
6486 box_out((*it).c_str()); box_eol();
6487 }
6488 box_end(true);
6489 }
6490 }
6491 else // Cancel
6492 {
6493 Akey = a;
6494 Bkey = b;
6495 Skey = s;
6496 Lkey = l;
6497 Rkey = r;
6498 Pkey = p;
6499 Exkey1 = ex1;
6500 Exkey2 = ex2;
6501 Exkey3 = ex3;
6502 Exkey4 = ex4;
6503 DUkey = du;
6504 DDkey = dd;
6505 DLkey = dl;
6506 DRkey = dr;
6507 cheat_modifier_keys[0] = mod1a;
6508 cheat_modifier_keys[1] = mod1b;
6509 cheat_modifier_keys[2] = mod2a;
6510 cheat_modifier_keys[3] = mod2b;
6511
6512 done=true;
6513 }
6514
6515 rest(1);
6516 }
6517
6518 return D_O_K;
6519 }
6520
6521 int32_t onGamepad()
6522 {
6523 if (al_get_num_joysticks() == 0)
6524 {
6525 InfoDialog("ZC", "No gamepads detected.").show();
6526 return D_O_K;
6527 }
6528
6529 int32_t a = Abtn;
6530 int32_t b = Bbtn;
6531 int32_t s = Sbtn;
6532 int32_t l = Lbtn;
6533 int32_t r = Rbtn;
6534 int32_t m = Mbtn;
6535 int32_t p = Pbtn;
6536 int32_t ex1 = Exbtn1;
6537 int32_t ex2 = Exbtn2;
6538 int32_t ex3 = Exbtn3;
6539 int32_t ex4 = Exbtn4;
6540 int32_t up = DUbtn;
6541 int32_t down = DDbtn;
6542 int32_t left = DLbtn;
6543 int32_t right = DRbtn;
6544 int32_t joy = joystick_index;
6545 int32_t stick_1 = js_stick_1_x_stick;
6546 int32_t stick_2 = js_stick_2_x_stick;
6547
6548 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6549 if(analog_movement)
6550 gamepad_dlg[56].flags|=D_SELECTED;
6551 else
6552 gamepad_dlg[56].flags&=~D_SELECTED;
6553
6554 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6555 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6556 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6557 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6558 // requires remapping every time.
6559 if (joystick_index >= al_get_num_joysticks())
6560 joystick_index = 0;
6561 gamepad_dlg[61].d2 = joystick_index;
6562
6563 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6564 if (!gamepad_dlg_cur_joystick)
6565 {
6566 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6567 return D_CLOSE;
6568 }
6569
6570 large_dialog(gamepad_dlg);
6571
6572 int32_t ret = do_zqdialog(gamepad_dlg,4);
6573
6574 if(ret == 4) //OK
6575 {
6576 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6577 joystick_index = gamepad_dlg[61].d2;
6578 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6579 if (!gamepad_dlg_cur_joystick)
6580 {
6581 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6582 return D_CLOSE;
6583 }
6584 js_stick_1_y_stick = js_stick_1_x_stick;
6585 js_stick_2_y_stick = js_stick_2_x_stick;
6586 save_control_configs(false);
6587 }
6588 else //Cancel
6589 {
6590 Abtn = a;
6591 Bbtn = b;
6592 Sbtn = s;
6593 Lbtn = l;
6594 Rbtn = r;
6595 Mbtn = m;
6596 Pbtn = p;
6597 Exbtn1 = ex1;
6598 Exbtn2 = ex2;
6599 Exbtn3 = ex3;
6600 Exbtn4 = ex4;
6601 DUbtn = up;
6602 DDbtn = down;
6603 DLbtn = left;
6604 DRbtn = right;
6605 joystick_index = joy;
6606 js_stick_1_x_stick = stick_1;
6607 js_stick_2_x_stick = stick_2;
6608 }
6609
6610 return D_O_K;
6611 }
6612
6613 int32_t onCheatKeys()
6614 {
6615 int32_t oldcheats[Cheat::Last][2];
6616 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6617
6618 bool done=false;
6619
6620 while(!done)
6621 {
6622 bool confirm = false;
6623 CheatKeysDialog(&confirm).show();
6624 if(confirm) // OK
6625 {
6626 std::vector<std::string> uniqueError;
6627 char buf[512];
6628 for(size_t q = 1; q < Cheat::Last; ++q)
6629 {
6630 if(cheatkeys[q][1] && !cheatkeys[q][0])
6631 {
6632 cheatkeys[q][0] = cheatkeys[q][1];
6633 cheatkeys[q][1] = 0;
6634 }
6635 }
6636 for(size_t q = 1; q < Cheat::Last; ++q)
6637 {
6638 if(!bindable_cheat((Cheat)q)) continue;
6639 for(size_t p = q+1; p < Cheat::Last; ++p)
6640 {
6641 if(!bindable_cheat((Cheat)p)) continue;
6642 for(size_t q2 = 0; q2 <= 1; ++q2)
6643 for(size_t p2 = 0; p2 <= 1; ++p2)
6644 {
6645 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6646 {
6647 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6648 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6649 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6650 get_keystr(cheatkeys[q][q2])));
6651 }
6652 }
6653 }
6654 }
6655 if(uniqueError.size() == 0)
6656 {
6657 done = true;
6658 save_cheatkeys();
6659 }
6660 else
6661 {
6662 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6663 box_out("Cannot have duplicate keybinds!"); box_eol();
6664 for(std::vector<std::string>::iterator it = uniqueError.begin();
6665 it != uniqueError.end(); ++it)
6666 {
6667 box_out((*it).c_str()); box_eol();
6668 }
6669 box_end(true);
6670 }
6671 }
6672 else // Cancel
6673 {
6674 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6675 done=true;
6676 }
6677 rest(1);
6678 }
6679
6680 return D_O_K;
6681 }
6682
6683 int32_t onSound()
6684 {
6685 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6686 {
6687 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6688 {
6689 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6690 }
6691 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6692 {
6693 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6694 }
6695 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6696 {
6697 emusic_volume = (int32_t)FFCore.usr_music_volume;
6698 }
6699 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6700 {
6701 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6702 }
6703 }
6704 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6705 {
6706 pan_style = (int32_t)FFCore.usr_panstyle;
6707 }
6708
6709 int32_t m = midi_volume;
6710 int32_t e = emusic_volume;
6711 int32_t s = sfx_volume;
6712 int32_t p = pan_style;
6713 pan_style = vbound(pan_style,0,3);
6714
6715 sound_dlg[0].dp2=get_zc_font(font_lfont);
6716
6717 large_dialog(sound_dlg);
6718
6719 midi_dp[1] = sound_dlg[6].x;
6720 midi_dp[2] = sound_dlg[6].y;
6721 emus_dp[1] = sound_dlg[8].x;
6722 emus_dp[2] = sound_dlg[8].y;
6723 sfx_dp[1] = sound_dlg[10].x;
6724 sfx_dp[2] = sound_dlg[10].y;
6725 pan_dp[1] = sound_dlg[11].x;
6726 pan_dp[2] = sound_dlg[11].y;
6727 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6728 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6729 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6730 sound_dlg[20].d2 = pan_style;
6731
6732 int32_t ret = do_zqdialog(sound_dlg,1);
6733
6734 if(ret==2)
6735 {
6736 master_volume(digi_volume,midi_volume);
6737 if (zcmusic)
6738 zcmusic_set_volume(zcmusic, emusic_volume);
6739
6740 int32_t temp_volume = sfx_volume;
6741 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6742 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6743 for(int32_t i=0; i<WAV_COUNT; ++i)
6744 {
6745 if(sfx_voice[i] >= 0)
6746 voice_set_volume(sfx_voice[i], temp_volume);
6747 }
6748 zc_set_config(sfx_sect,"midi",midi_volume);
6749 zc_set_config(sfx_sect,"sfx",sfx_volume);
6750 zc_set_config(sfx_sect,"emusic",emusic_volume);
6751 zc_set_config(sfx_sect,"pan",pan_style);
6752 }
6753 else
6754 {
6755 midi_volume = m;
6756 emusic_volume = e;
6757 sfx_volume = s;
6758 pan_style = p;
6759 }
6760
6761 return D_O_K;
6762 }
6763
6764 int32_t queding(char const* s1, char const* s2, char const* s3)
6765 {
6766 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6767 }
6768
6769 int32_t onQuit()
6770 {
6771 if(Playing)
6772 {
6773 int32_t ret=0;
6774
6775 if(get_qr(qr_NOCONTINUE))
6776 {
6777 if(standalone_mode)
6778 {
6779 ret=queding("End current game?",
6780 "The continue screen is disabled; the game",
6781 "will be reloaded from the last save.");
6782 }
6783 else
6784 {
6785 ret=queding("End current game?",
6786 "The continue screen is disabled. You will",
6787 "be returned to the file select screen.");
6788 }
6789 }
6790 else
6791 ret=queding("End current game?",NULL,NULL);
6792
6793 if(ret==1)
6794 {
6795 disableClickToFreeze=false;
6796 Quit=qQUIT;
6797
6798 // Trying to evade a door repair charge?
6799 if(repaircharge)
6800 {
6801 game->change_drupy(-repaircharge);
6802 repaircharge=0;
6803 }
6804
6805 return D_CLOSE;
6806 }
6807 }
6808
6809 return D_O_K;
6810 }
6811
6812 int32_t onTryQuitMenu()
6813 {
6814 return onTryQuit(true);
6815 }
6816
6817 int32_t onTryQuit(bool inMenu)
6818 {
6819 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6820 {
6821 if(active_cutscene.can_f6())
6822 {
6823 if(get_qr(qr_OLD_F6))
6824 {
6825 if(inMenu) onQuit();
6826 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6827 }
6828 else
6829 {
6830 disableClickToFreeze=false;
6831 GameFlags |= GAMEFLAG_TRYQUIT;
6832 }
6833 return D_CLOSE;
6834 }
6835 else active_cutscene.error();
6836 }
6837
6838 return D_O_K;
6839 }
6840
6841 int32_t onReset()
6842 {
6843 if(queding(" Reset system? ",NULL,NULL)==1)
6844 {
6845 disableClickToFreeze=false;
6846 Quit=qRESET;
6847 replay_quit();
6848 return D_CLOSE;
6849 }
6850
6851 return D_O_K;
6852 }
6853
6854 int32_t onExit()
6855 {
6856 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6857 {
6858 Quit=qEXIT;
6859 return D_CLOSE;
6860 }
6861
6862 return D_O_K;
6863 }
6864
6865 int32_t onDebug()
6866 {
6867 if(debug_enabled)
6868 set_debug(!get_debug());
6869 return D_O_K;
6870 }
6871
6872 int32_t onHeartBeep()
6873 {
6874 heart_beep=!heart_beep;
6875 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6876 return D_O_K;
6877 }
6878
6879 int32_t onSaveIndicator()
6880 {
6881 use_save_indicator = use_save_indicator ? 0 : 1;
6882 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6883 return D_O_K;
6884 }
6885
6886 int32_t onEpilepsy()
6887 {
6888 if(jwin_alert3(
6889 "Epilepsy Flash Reduction",
6890 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6891 "Disabling this will restore standard flash and wavy behaviour.",
6892 "Proceed?",
6893 "&Yes",
6894 "&No",
6895 NULL,
6896 'y',
6897 'n',
6898 0,
6899 get_zc_font(font_lfont)) == 1)
6900 {
6901 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6902 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6903 }
6904 return D_O_K;
6905 }
6906
6907 bool rc = false;
6908
6909 static DIALOG getnum_dlg[] =
6910 {
6911 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6912 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6913 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6914 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6915 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6916 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6917 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6918 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6919 };
6920
6921 int32_t getnumber(const char *prompt,int32_t initialval)
6922 {
6923 char buf[20];
6924 sprintf(buf,"%d",initialval);
6925 getnum_dlg[0].dp=(void *)prompt;
6926 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6927 getnum_dlg[2].dp=buf;
6928
6929 large_dialog(getnum_dlg);
6930
6931 if(do_zqdialog(getnum_dlg,2)==3)
6932 return atoi(buf);
6933
6934 return initialval;
6935 }
6936
6937 int32_t onLife()
6938 {
6939 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6940 cheats_enqueue(Cheat::Life, value);
6941 return D_O_K;
6942 }
6943
6944 int32_t onHeartC()
6945 {
6946 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6947 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6948 cheats_enqueue(Cheat::MaxLife, max_life);
6949 cheats_enqueue(Cheat::Life, life);
6950 return D_O_K;
6951 }
6952
6953 int32_t onMagicC()
6954 {
6955 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6956 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6957 cheats_enqueue(Cheat::MaxMagic, max_magic);
6958 cheats_enqueue(Cheat::Magic, magic);
6959 return D_O_K;
6960 }
6961
6962 int32_t onRupies()
6963 {
6964 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6965 cheats_enqueue(Cheat::Rupies, value);
6966 return D_O_K;
6967 }
6968
6969 int32_t onMaxBombs()
6970 {
6971 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6972 cheats_enqueue(Cheat::MaxBombs, value);
6973 cheats_enqueue(Cheat::Bombs, value);
6974 return D_O_K;
6975 }
6976
6977 int32_t onRefillLife()
6978 {
6979 cheats_enqueue(Cheat::Life, game->get_maxlife());
6980 return D_O_K;
6981 }
6982 int32_t onRefillMagic()
6983 {
6984 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6985 return D_O_K;
6986 }
6987 int32_t onClock()
6988 {
6989 cheats_enqueue(Cheat::Clock);
6990 return D_O_K;
6991 }
6992
6993 int32_t onQstPath()
6994 {
6995 char initial_path[2048];
6996 chop_path(qstdir);
6997 strcpy(initial_path, qstdir);
6998
6999 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7000 {
7001 char* path = result->data();
7002 chop_path(path);
7003 fix_filename_case(path);
7004 fix_filename_slashes(path);
7005 strcpy(qstdir,path);
7006 strcpy(qstpath,qstdir);
7007 zc_set_config("zeldadx","quest_dir",qstdir);
7008 flush_config_file();
7009 }
7010
7011 return D_O_K;
7012 }
7013
7014 #include "dialog/cheat_dialog.h"
7015 int32_t onCheat()
7016 {
7017 call_setcheat_dialog();
7018 game->set_cheat(maxcheat);
7019 if(cheat) game->did_cheat(true);
7020 return D_O_K;
7021 }
7022
7023 int32_t onCheatRupies()
7024 {
7025 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7026 return D_O_K;
7027 }
7028
7029 int32_t onCheatArrows()
7030 {
7031 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7032 return D_O_K;
7033 }
7034
7035 int32_t onCheatBombs()
7036 {
7037 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7038 return D_O_K;
7039 }
7040
7041 // *** screen saver
7042
7043 18496351 int32_t after_time()
7044 {
7045
1/2
✓ Branch 0 taken 18496351 times.
✗ Branch 1 not taken.
18496351 if(ss_enable == 0)
7046 return INT_MAX;
7047
7048
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
18496351 if(ss_after <= 0)
7049 return 5 * 60;
7050
7051
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
18496351 if(ss_after <= 3)
7052 return ss_after * 15 * 60;
7053
7054
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496351 times.
18496351 if(ss_after <= 13)
7055 return (ss_after - 3) * 60 * 60;
7056
7057 18496351 return MAX_IDLE + 1;
7058 18496351 }
7059
7060 static const char *after_str[15] =
7061 {
7062 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7063 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7064 "Never"
7065 };
7066
7067 const char *after_list(int32_t index, int32_t *list_size)
7068 {
7069 if(index < 0)
7070 {
7071 *list_size = 15;
7072 return NULL;
7073 }
7074
7075 return after_str[index];
7076 }
7077
7078 399 static ListData after__list(after_list, &font);
7079
7080 static DIALOG scrsaver_dlg[] =
7081 {
7082 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7083 399 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7084 399 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7085 399 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7086 399 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7087 399 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7088 399 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7089 399 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7090 399 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7091 399 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7092 399 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7093 399 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7094 399 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7095 399 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7096 };
7097
7098 int32_t onScreenSaver()
7099 {
7100 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7101 int32_t oldcfgs[3];
7102 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7103 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7104 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7105
7106 large_dialog(scrsaver_dlg);
7107
7108 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7109
7110 if(ret == 8 || ret == 9)
7111 {
7112 ss_after = scrsaver_dlg[5].d1;
7113 ss_speed = scrsaver_dlg[6].d2;
7114 ss_density = scrsaver_dlg[7].d2;
7115 if(oldcfgs[0] != ss_after)
7116 zc_set_config(cfg_sect,"ss_after",ss_after);
7117 if(oldcfgs[1] != ss_speed)
7118 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7119 if(oldcfgs[2] != ss_density)
7120 zc_set_config(cfg_sect,"ss_density",ss_density);
7121 }
7122
7123 if(ret == 9)
7124 // preview Screen Saver
7125 {
7126 clear_keybuf();
7127 Matrix(ss_speed, ss_density, 30);
7128 system_pal(true);
7129 sys_mouse();
7130 }
7131
7132 return D_O_K;
7133 }
7134
7135 /***** Menus *****/
7136
7137 enum
7138 {
7139 MENUID_GAME_LOADQUEST,
7140 MENUID_GAME_ENDGAME,
7141 };
7142
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu game_menu
7143 3192 {
7144
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "&Continue","ESC", onContinue },
7145
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7146
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7147
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7148
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7149 #ifdef __EMSCRIPTEN__
7150 { "&Reset","F7", onReset },
7151 #elif defined(ALLEGRO_MACOSX)
7152 { "&Reset","F7", onReset },
7153 { "&Quit","F8", onExit },
7154 #else
7155
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "&Reset","F9", onReset },
7156
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "&Quit","F10", onExit },
7157 #endif
7158 };
7159
7160
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu snapshot_format_menu
7161 2793 {
7162
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7163
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7164
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7165
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7166
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7167
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7168 };
7169
7170
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu bottom_8_pixels_menu
7171 1596 {
7172
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7173
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&On", std::bind(onSetBottom8Pixels, 1) },
7174
4/8
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 399 times.
✗ Branch 7 not taken.
399 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7175 };
7176
7177
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu controls_menu
7178 1596 {
7179
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Key&board...", onKeyboard },
7180
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Gamepad...", onGamepad },
7181
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Cheat Keys...", onCheatKeys },
7182 };
7183
7184
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu name_entry_mode_menu
7185 1596 {
7186
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Keyboard", onKeyboardEntry },
7187
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Letter Grid", onLetterGridEntry },
7188
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Extended Letter Grid", onExtLetterGridEntry },
7189 };
7190
7191 static void set_controls_menu_active()
7192 {
7193
7194 }
7195
7196 enum
7197 {
7198 MENUID_WINDOW_LOCK_ASPECT,
7199 MENUID_WINDOW_LOCK_INTSCALE,
7200 MENUID_WINDOW_SAVE_SIZE,
7201 MENUID_WINDOW_SAVE_POS,
7202 MENUID_WINDOW_STRETCH,
7203 };
7204
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu window_menu
7205 2394 {
7206
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7207
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7208
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7209
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7210
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7211 };
7212 void call_zc_options_dlg();
7213 enum
7214 {
7215 MENUID_OPTIONS_PAUSE_BG,
7216 MENUID_OPTIONS_EPILEPSYPROT,
7217 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7218 };
7219
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu options_menu
7220 3192 {
7221
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Name &Entry Mode", &name_entry_mode_menu },
7222
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "S&napshot Format", &snapshot_format_menu },
7223
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Window Settings", &window_menu },
7224
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7225
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7226
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7227
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "More Options", call_zc_options_dlg },
7228 };
7229 enum
7230 {
7231 MENUID_SETTINGS_CONTROLS,
7232 MENUID_SETTINGS_CAPFPS,
7233 MENUID_SETTINGS_SHOWFPS,
7234 MENUID_SETTINGS_SHOWTIME,
7235 MENUID_SETTINGS_CLICK_FREEZE,
7236 MENUID_SETTINGS_TRANSLAYERS,
7237 MENUID_SETTINGS_NESQUIT,
7238 MENUID_SETTINGS_VOLKEYS,
7239 MENUID_SETTINGS_HEARTBEEP,
7240 MENUID_SETTINGS_SAVEINDICATOR,
7241 MENUID_SETTINGS_DEBUG,
7242 };
7243
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu settings_menu
7244 6783 {
7245
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Sound...", onSound },
7246
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7247
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7248
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Options", &options_menu },
7249
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7250
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7251
3/6
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 399 times.
✗ Branch 5 not taken.
399 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7252
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7253
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7254
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7255
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7256
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7257
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7258
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7259
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7260
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7261 };
7262
7263 enum
7264 {
7265 MENUID_MISC_FULLSCREEN,
7266 MENUID_MISC_VIDMODE,
7267 MENUID_MISC_QUEST_INFO,
7268 MENUID_MISC_QUEST_DIR,
7269 MENUID_MISC_CONSOLE,
7270 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7271 };
7272
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu misc_menu
7273 5985 {
7274
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&About...", onAbout },
7275 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7276 // { "&Credits...", onCredits },
7277
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7278
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7279
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7280
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7281
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Quest &MIDI Info...", onMIDICredits },
7282
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7283
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7284
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Take &Snapshot F12", onSnapshot },
7285
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Sc&reen Saver...", onScreenSaver },
7286
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Save ZC Configuration", OnSaveZCConfig },
7287
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7288
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7289
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Clear Directory Cache", OnnClearQuestDir },
7290 };
7291
7292 enum
7293 {
7294 MENUID_REFILL_ARROWS,
7295 };
7296
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu refill_menu
7297 2394 {
7298
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Life", onRefillLife },
7299
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Magic", onRefillMagic },
7300
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Bombs", onCheatBombs },
7301
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Rupees", onCheatRupies },
7302
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7303 };
7304
7305 enum
7306 {
7307 MENUID_SHOW_L0,
7308 MENUID_SHOW_L1,
7309 MENUID_SHOW_L2,
7310 MENUID_SHOW_L3,
7311 MENUID_SHOW_L4,
7312 MENUID_SHOW_L5,
7313 MENUID_SHOW_L6,
7314 MENUID_SHOW_OVER,
7315 MENUID_SHOW_PUSH,
7316 MENUID_SHOW_FFC,
7317 MENUID_SHOW_SPR,
7318 MENUID_SHOW_SCRIPTNAME,
7319 MENUID_SHOW_SOLIDITY,
7320 MENUID_SHOW_HITBOX,
7321 MENUID_SHOW_EFFECT,
7322 };
7323
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu show_menu
7324 7581 {
7325
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7326
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7327
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7328
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7329
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7330
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7331
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7332
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7333
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7334
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7335
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7336
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7337
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7338
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 {},
7339
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7340
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7341
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7342
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Info Opacity", onShowInfoOpacity },
7343 };
7344
7345 enum
7346 {
7347 MENUID_CHEAT_CHOP_L1,
7348 MENUID_CHEAT_CHOP_L2,
7349 MENUID_CHEAT_CHOP_L3,
7350 MENUID_CHEAT_CHOP_L4,
7351 MENUID_CHEAT_INVULN,
7352 MENUID_CHEAT_NOCLIP,
7353 MENUID_CHEAT_IGNORESV,
7354 MENUID_CHEAT_GOFAST,
7355 };
7356
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 static NewMenu cheat_menu
7357 6783 {
7358
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Set &Cheat", onCheat },
7359
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 { MENUID_CHEAT_CHOP_L1 },
7360
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Re&fill", &refill_menu },
7361
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 { MENUID_CHEAT_CHOP_L2 },
7362
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7363
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Ma&x Bombs...", onMaxBombs },
7364
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Heart Containers...", onHeartC },
7365
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Magic Containers...", onMagicC },
7366
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 { MENUID_CHEAT_CHOP_L3 },
7367
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Hero Data...", onCheatConsole },
7368
1/2
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
399 { MENUID_CHEAT_CHOP_L4 },
7369
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7370
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7371
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7372
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Kill All Enemies", onKillCheat },
7373
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Trigger &Secrets", onSecretsCheat },
7374
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Trigger Secrets Perm", onSecretsCheatPerm },
7375
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Show/Hide Layer", &show_menu },
7376
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "Toggle &Light", onLightSwitch },
7377
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Goto Location...", onGoTo },
7378 };
7379
7380 #if DEVLEVEL > 0
7381 int32_t devLogging();
7382 int32_t devDebug();
7383 int32_t devTimestmp();
7384 #if DEVLEVEL > 1
7385 int32_t setCheat();
7386 #endif //DEVLEVEL > 1
7387 enum
7388 {
7389 MENUID_DEV_LOGGING,
7390 MENUID_DEV_DEBUG,
7391 MENUID_DEV_TIMESTAMP,
7392 MENUID_DEV_SETCHEAT,
7393 };
7394 static NewMenu dev_menu
7395 {
7396 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7397 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7398 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7399 #if DEVLEVEL > 1
7400 {},
7401 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7402 #endif //DEVLEVEL > 1
7403 };
7404 int32_t devLogging()
7405 {
7406 dev_logging = !dev_logging;
7407 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7408 return D_O_K;
7409 }
7410 // int32_t devDebug()
7411 // {
7412 // dev_debug = !dev_debug;
7413 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7414 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7415 // return D_O_K;
7416 // }
7417 int32_t devTimestmp()
7418 {
7419 dev_timestmp = !dev_timestmp;
7420 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7421 return D_O_K;
7422 }
7423 #if DEVLEVEL > 1
7424 int32_t setCheat()
7425 {
7426 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7427 return D_O_K;
7428 }
7429 #endif //DEVLEVEL > 1
7430 #endif //DEVLEVEL > 0
7431
7432 enum
7433 {
7434 MENUID_PLAYER_CHEAT,
7435 };
7436
1/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
399 TopMenu the_player_menu
7437 2394 {
7438
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Game", &game_menu },
7439
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Settings", &settings_menu },
7440
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7441
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&Replay", &replay_menu },
7442
2/4
✓ Branch 0 taken 399 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 399 times.
✗ Branch 3 not taken.
399 { "&ZC", &misc_menu },
7443 #if DEVLEVEL > 0
7444 { "&Dev", &dev_menu },
7445 #endif
7446 };
7447
7448 int32_t onPauseInBackground()
7449 {
7450 if(jwin_alert3(
7451 "Toggle Pause In Background",
7452 "This action will change whether ZC Player pauses when the window loses focus.",
7453 "",
7454 "Proceed?",
7455 "&Yes",
7456 "&No",
7457 NULL,
7458 'y',
7459 'n',
7460 0,
7461 get_zc_font(font_lfont)) == 1)
7462 {
7463 pause_in_background = pause_in_background ? 0 : 1;
7464 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7465 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7466 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7467 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7468 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7469 }
7470 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7471 return D_O_K;
7472 }
7473
7474 int32_t onKeyboardEntry()
7475 {
7476 NameEntryMode=0;
7477 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7478 return D_O_K;
7479 }
7480
7481 int32_t onLetterGridEntry()
7482 {
7483 NameEntryMode=1;
7484 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7485 return D_O_K;
7486 }
7487
7488 int32_t onExtLetterGridEntry()
7489 {
7490 NameEntryMode=2;
7491 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7492 return D_O_K;
7493 }
7494
7495 static BITMAP* oldscreen;
7496 int32_t onFullscreenMenu()
7497 {
7498 PALETTE oldpal;
7499 get_palette(oldpal);
7500
7501 fullscreen = !fullscreen;
7502 all_toggle_fullscreen(fullscreen);
7503 zc_set_config("zeldadx","fullscreen",fullscreen);
7504
7505 zc_set_palette(oldpal);
7506 gui_mouse_focus=0;
7507 extern int32_t switch_type;
7508 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7509 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7510 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7511 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7512 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7513 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7514
7515 return D_O_K;
7516 }
7517
7518 304 void fix_menu()
7519 {
7520
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 304 times.
304 if(!debug_enabled)
7521 304 settings_menu.chop_index = 13;
7522 304 }
7523
7524 int32_t onSetSnapshotFormat(SnapshotType format)
7525 {
7526 SnapshotFormat = format;
7527 zc_set_config("zeldadx", "snapshot_format", format);
7528 snapshot_format_menu.select_only_index(format);
7529 return D_O_K;
7530 }
7531
7532 int32_t onSetBottom8Pixels(int option)
7533 {
7534 ShowBottomPixels = option;
7535 zc_set_config("zeldadx", "bottom_8_px", option);
7536 bottom_8_pixels_menu.select_only_index(option);
7537
7538 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7539 bool value = false;
7540 if (option == 0)
7541 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7542 else if (option == 1)
7543 value = false;
7544 else if (option == 2)
7545 value = true;
7546 enqueue_qr_change(qr, value);
7547
7548 return D_O_K;
7549 }
7550
7551 2895 void updateShowBottomPixels()
7552 {
7553 // It's too tricky the allow modifying the screen height between opening and closing the
7554 // active subscreen.
7555
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2869 times.
2895 if (subscreen_open)
7556 26 return;
7557
7558
1/2
✓ Branch 0 taken 2869 times.
✗ Branch 1 not taken.
2869 if (!GameLoaded)
7559 show_bottom_8px = false;
7560 else
7561 2869 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7562
7563 2869 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7564
2/2
✓ Branch 0 taken 2779 times.
✓ Branch 1 taken 90 times.
2869 if (framebuf->h != target_bitmap_height)
7565 {
7566 90 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7567 90 clear_bitmap(new_framebuf);
7568 90 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7569
7570 90 destroy_bitmap(framebuf);
7571 90 destroy_bitmap(script_menu_buf);
7572 90 destroy_bitmap(f6_menu_buf);
7573 90 destroy_bitmap(darkscr_bmp);
7574 90 destroy_bitmap(darkscr_bmp_trans);
7575
7576 90 framebuf = new_framebuf;
7577 90 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7578 90 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7579 90 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7580 90 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7581
7582 90 rti_game.a4_bitmap = framebuf;
7583 90 rti_game.set_size(framebuf->w, framebuf->h);
7584 90 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7585 90 al_destroy_bitmap(rti_game.bitmap);
7586 90 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7587 90 al_destroy_bitmap(rti_infolayer.bitmap);
7588 90 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7589 90 }
7590 2895 }
7591
7592 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7593 {
7594 PALETTE tmp;
7595
7596 for(int32_t i=0; i<256; i++)
7597 {
7598 tmp[i].r=r;
7599 tmp[i].g=g;
7600 tmp[i].b=b;
7601 }
7602
7603 fade_interpolate(src,tmp,dest,pos,from,to);
7604 }
7605
7606 55 void system_pal(bool force)
7607 {
7608
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
55 if(is_sys_pal && !force) return;
7609 55 is_sys_pal = true;
7610 55 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7611 55 hw_palette = &syspal;
7612 55 update_hw_pal = true;
7613 55 }
7614
7615 static uint32_t entered_sys_pal = 0;
7616 55 void enter_sys_pal()
7617 {
7618
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(is_sys_pal)
7619 {
7620 if(entered_sys_pal)
7621 ++entered_sys_pal;
7622 return;
7623 }
7624 55 sys_mouse();
7625 55 system_pal(true);
7626 55 ++entered_sys_pal;
7627 55 }
7628 55 void exit_sys_pal()
7629 {
7630
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(entered_sys_pal)
7631 {
7632
1/2
✓ Branch 0 taken 55 times.
✗ Branch 1 not taken.
55 if(!--entered_sys_pal)
7633 {
7634 55 game_pal();
7635 55 game_mouse();
7636 55 }
7637 55 }
7638 55 }
7639
7640 void switch_out_callback()
7641 {
7642 if (pause_in_background && !MenuOpen)
7643 {
7644 System();
7645 }
7646 }
7647
7648 void switch_in_callback()
7649 {
7650 }
7651
7652 1149 void game_pal()
7653 {
7654 1149 is_sys_pal = false;
7655 1149 entered_sys_pal = 0;
7656 1149 hw_palette = &RAMpal;
7657 1149 update_hw_pal = true;
7658 1149 }
7659
7660 static char bar_str[] = "";
7661
7662 55 void music_pause()
7663 {
7664 //al_pause_duh(tmplayer);
7665 55 zcmusic_pause(zcmusic, ZCM_PAUSE);
7666
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(zcmixer->oldtrack)
7667 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7668 55 zc_midi_pause();
7669 55 }
7670
7671 void music_resume()
7672 {
7673 //al_resume_duh(tmplayer);
7674 zcmusic_pause(zcmusic, ZCM_RESUME);
7675 if (zcmixer->oldtrack)
7676 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7677 zc_midi_resume();
7678 }
7679
7680 7910 void music_stop()
7681 {
7682 //al_stop_duh(tmplayer);
7683 //unload_duh(tmusic);
7684 //tmusic=NULL;
7685 //tmplayer=NULL;
7686 7910 zcmusic_stop(zcmusic);
7687 7910 zcmusic_unload_file(zcmusic);
7688
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7910 times.
7910 if (zcmixer->oldtrack)
7689 {
7690 zcmusic_stop(zcmixer->oldtrack);
7691 zcmusic_unload_file(zcmixer->oldtrack);
7692 }
7693 7910 zcmixer->newtrack = NULL;
7694 7910 zc_stop_midi();
7695 7910 currmidi=-1;
7696 7910 }
7697
7698 bool reload_fonts = false;
7699 void System()
7700 {
7701 mouse_down = gui_mouse_b();
7702 music_pause();
7703 pause_all_sfx();
7704 MenuOpen = true;
7705 enter_sys_pal();
7706 // FONT *oldfont=font;
7707 // font=tfont;
7708
7709 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7710 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7711
7712 #if DEVLEVEL > 1
7713 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7714 #endif
7715 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7716 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7717 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7718 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7719 clear_keybuf();
7720
7721 clear_bitmap(menu_bmp);
7722 oldscreen = screen;
7723 screen = menu_bmp;
7724
7725 the_player_menu.reset_state();
7726 the_player_menu.position(0, 0);
7727
7728 bool running = true;
7729 bool esc = key[KEY_ESC] || cMbtn();
7730 bool autopop = esc;
7731 do
7732 {
7733 if(reload_fonts)
7734 {
7735 init_custom_fonts();
7736 clear_bitmap(menu_bmp);
7737 broadcast_dialog_message(MSG_DRAW, 0);
7738 reload_fonts = false;
7739 }
7740 if(handle_close_btn_quit())
7741 break;
7742
7743 //update submenus
7744 {
7745 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7746 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7747 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7748 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7749 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7750 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7751 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7752 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7753
7754 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7755 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7756 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7757 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7758 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7759
7760 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7761 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7762 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7763
7764 name_entry_mode_menu.select_only_index(NameEntryMode);
7765
7766 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7767 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7768
7769 bool nocheat = (replay_is_replaying() || !Playing
7770 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7771 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7772 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7773 cheat_menu.chop_index.reset();
7774 if(cheat < 4)
7775 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7776 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7777 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, toogam);
7778 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7779 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7780
7781 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7782 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7783 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7784 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7785 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7786 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7787 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7788 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7789 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7790 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7791 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7792 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7793 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7794 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7795 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7796
7797 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7798 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7799
7800 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7801 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7802
7803 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7804 #ifdef HAS_CURL
7805 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7806 #endif
7807 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7808 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7809 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7810
7811 snapshot_format_menu.select_only_index(SnapshotFormat);
7812 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7813 }
7814
7815 if(debug_enabled)
7816 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7817
7818 if(autopop)
7819 clear_keybuf();
7820 the_player_menu.run(true);
7821 if(autopop)
7822 {
7823 the_player_menu.pop_sub(0, &the_player_menu);
7824 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7825 autopop = false;
7826 update_hw_screen();
7827 }
7828
7829 update_hw_screen();
7830
7831 auto mb = gui_mouse_b();
7832 if(XOR(mb, mouse_down))
7833 {
7834 if(!the_player_menu.has_mouse())
7835 if(mb)
7836 break;
7837 mouse_down = mb;
7838 }
7839
7840 if(input_idle(true) > after_time())
7841 // run Screeen Saver
7842 {
7843 // Screen saver enabled for now.
7844 clear_keybuf();
7845 Matrix(ss_speed, ss_density, 0);
7846 system_pal(true);
7847 sys_mouse();
7848 }
7849
7850 poll_keyboard();
7851 if(esc)
7852 {
7853 if(!key[KEY_ESC])
7854 esc = false;
7855 }
7856
7857 if(keypressed() && !CHECK_ALT) //System hotkeys
7858 {
7859 auto c = peekkey();
7860 bool eatkey = true;
7861 switch(c>>8)
7862 {
7863 //Spare keys used by the menu
7864 case KEY_UP:
7865 case KEY_DOWN:
7866 case KEY_LEFT:
7867 case KEY_RIGHT:
7868 eatkey = false;
7869 break;
7870 case KEY_F1:
7871 onThrottleFPS();
7872 break;
7873 case KEY_F2:
7874 onShowFPS();
7875 break;
7876 case KEY_F6:
7877 onTryQuitMenu();
7878 break;
7879 #ifndef ALLEGRO_MACOSX
7880 case KEY_F9:
7881 onReset();
7882 break;
7883 case KEY_F10:
7884 onExit();
7885 break;
7886 #else
7887 case KEY_F7:
7888 onReset();
7889 break;
7890 case KEY_F8:
7891 onExit();
7892 break;
7893 #endif
7894 case KEY_F12:
7895 onSnapshot();
7896 break;
7897 case KEY_TAB:
7898 onDebug();
7899 break;
7900 case KEY_ESC:
7901 if(!esc)
7902 running = false;
7903 break;
7904 }
7905 if(eatkey)
7906 readkey();
7907 }
7908 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7909 break;
7910 }
7911 while(running);
7912
7913 screen = oldscreen;
7914
7915 mouse_down=gui_mouse_b();
7916 MenuOpen = false;
7917 if(Quit)
7918 {
7919 kill_sfx();
7920 music_stop();
7921 update_hw_screen();
7922 }
7923 else
7924 {
7925 music_resume();
7926 resume_all_sfx();
7927
7928 if(rc)
7929 ringcolor(false);
7930 }
7931 exit_sys_pal();
7932
7933 eat_buttons();
7934
7935 rc=false;
7936 clear_keybuf();
7937
7938 zc_init_apply_cheat_delta();
7939 }
7940
7941 304 void fix_dialogs()
7942 {
7943 304 jwin_center_dialog(about_dlg);
7944 304 jwin_center_dialog(gamepad_dlg);
7945 304 jwin_center_dialog(credits_dlg);
7946 304 jwin_center_dialog(gamemode_dlg);
7947 304 jwin_center_dialog(getnum_dlg);
7948 304 jwin_center_dialog(goto_dlg);
7949 304 jwin_center_dialog(keyboard_control_dlg);
7950 304 jwin_center_dialog(midi_dlg);
7951 304 jwin_center_dialog(quest_dlg);
7952 304 jwin_center_dialog(scrsaver_dlg);
7953 304 jwin_center_dialog(sound_dlg);
7954 304 jwin_center_dialog(triforce_dlg);
7955 304 }
7956
7957 4320 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7958 {
7959
3/4
✓ Branch 0 taken 4320 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4298 times.
✓ Branch 3 taken 22 times.
4320 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7960 }
7961
7962 289 int32_t get_emusic_volume()
7963 {
7964 289 int32_t temp_volume = emusic_volume;
7965
2/4
✓ Branch 0 taken 289 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 289 times.
✗ Branch 3 not taken.
289 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7966 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7967
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 289 times.
289 if (!zcmusic)
7968 289 return temp_volume;
7969 return (temp_volume * zcmusic->fadevolume) / 10000;
7970 289 }
7971
7972 int32_t get_zcmusicpos()
7973 {
7974 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7975 return debugtracething;
7976 return 0;
7977 }
7978
7979 void set_zcmusicpos(int32_t position)
7980 {
7981 zcmusic_set_curpos(zcmusic, position);
7982 }
7983
7984 void set_zcmusicspeed(int32_t speed)
7985 {
7986 zcmusic_set_speed(zcmusic, speed);
7987 }
7988
7989 int32_t get_zcmusiclen()
7990 {
7991 return zcmusic_get_length(zcmusic);
7992 }
7993
7994 3 void set_zcmusicloop(double start, double end)
7995 {
7996 3 zcmusic_set_loop(zcmusic, start, end);
7997 3 }
7998
7999 64162 void jukebox(int32_t index,int32_t loop)
8000 {
8001
1/2
✓ Branch 0 taken 64162 times.
✗ Branch 1 not taken.
64162 if (is_headless())
8002 64162 return;
8003
8004 music_stop();
8005
8006 if(index<0) index=MAXMIDIS-1;
8007
8008 if(index>=MAXMIDIS) index=0;
8009
8010 music_stop();
8011
8012 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8013 // stuck notes when a song stops. This fixes it.
8014 if(strcmp(midi_driver->name, "DIGMID")==0)
8015 zc_set_volume(0, 0);
8016
8017 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8018 zc_play_midi(tunes[index].data,loop);
8019
8020 if(tunes[index].start>0)
8021 zc_midi_seek(tunes[index].start);
8022
8023 midi_loop_start = tunes[index].loop_start;
8024 midi_loop_end = tunes[index].loop_end;
8025
8026 currmidi=index;
8027 master_volume(digi_volume, midi_volume);
8028 //midi_paused=false;
8029 64162 }
8030
8031 64162 void jukebox(int32_t index)
8032 {
8033
1/2
✓ Branch 0 taken 64162 times.
✗ Branch 1 not taken.
64162 if(index<0) index=MAXMIDIS-1;
8034
8035
1/2
✓ Branch 0 taken 64162 times.
✗ Branch 1 not taken.
64162 if(index>=MAXMIDIS) index=0;
8036
8037 // do nothing if it's already playing
8038
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64162 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64162 if(index==currmidi && midi_pos>=0)
8039 {
8040 return;
8041 }
8042
8043 64162 jukebox(index,tunes[index].loop);
8044 64162 }
8045
8046 100 void play_DmapMusic()
8047 {
8048
1/2
✓ Branch 0 taken 100 times.
✗ Branch 1 not taken.
100 if (is_headless())
8049 100 return;
8050
8051 static char tfile[2048];
8052 static int32_t ttrack=0;
8053 bool domidi=false;
8054
8055 int32_t fadeoutframes = 0;
8056 if (zcmusic != NULL)
8057 fadeoutframes = zcmusic->fadeoutframes;
8058
8059 if(DMaps[cur_dmap].tmusic[0]!=0)
8060 {
8061 if(zcmusic==NULL ||
8062 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8063 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8064 {
8065 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8066 {
8067 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8068 {
8069 if (zcmusic != NULL)
8070 {
8071 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8072 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8073 }
8074 }
8075 }
8076 else
8077 {
8078 if (zcmusic != NULL)
8079 {
8080 zcmusic_stop(zcmusic);
8081 zcmusic_unload_file(zcmusic);
8082 zcmusic = NULL;
8083 zcmixer->newtrack = NULL;
8084 }
8085
8086 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8087 zcmixer->newtrack = zcmusic;
8088
8089 if (zcmusic != NULL)
8090 {
8091 zc_stop_midi();
8092 strcpy(tfile, DMaps[cur_dmap].tmusic);
8093 zcmusic_play(zcmusic, emusic_volume);
8094 int32_t temptracks = 0;
8095 temptracks = zcmusic_get_tracks(zcmusic);
8096 temptracks = (temptracks < 2) ? 1 : temptracks;
8097 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8098 zcmusic_change_track(zcmusic, ttrack);
8099 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8100 }
8101 else
8102 {
8103 tfile[0] = 0;
8104 domidi = true;
8105 }
8106 }
8107 }
8108 }
8109 else
8110 {
8111 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8112 {
8113 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8114 }
8115 else
8116 {
8117 domidi = true;
8118 }
8119 }
8120
8121 if(domidi)
8122 {
8123 int32_t m=DMaps[cur_dmap].midi;
8124
8125 switch(m)
8126 {
8127 case 1:
8128 jukebox(ZC_MIDI_OVERWORLD);
8129 break;
8130
8131 case 2:
8132 jukebox(ZC_MIDI_DUNGEON);
8133 break;
8134
8135 case 3:
8136 jukebox(ZC_MIDI_LEVEL9);
8137 break;
8138
8139 default:
8140 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8141 jukebox(m+MIDIOFFSET_DMAP);
8142 else
8143 music_stop();
8144 }
8145 }
8146 100 }
8147
8148 35680 void playLevelMusic()
8149 {
8150
1/2
✓ Branch 0 taken 35680 times.
✗ Branch 1 not taken.
35680 if (is_headless())
8151 35680 return;
8152
8153 int32_t m=hero_scr->screen_midi;
8154
8155 switch(m)
8156 {
8157 case -2:
8158 music_stop();
8159 break;
8160
8161 case -1:
8162 play_DmapMusic();
8163 break;
8164
8165 case 1:
8166 jukebox(ZC_MIDI_OVERWORLD);
8167 break;
8168
8169 case 2:
8170 jukebox(ZC_MIDI_DUNGEON);
8171 break;
8172
8173 case 3:
8174 jukebox(ZC_MIDI_LEVEL9);
8175 break;
8176
8177 default:
8178 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8179 jukebox(m+MIDIOFFSET_MAPSCR);
8180 else
8181 music_stop();
8182 }
8183 35680 }
8184
8185 4320 void master_volume(int32_t dv,int32_t mv)
8186 {
8187
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2312 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 345 times.
✓ Branch 4 taken 2312 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 345 times.
4320 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8188
8189
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2316 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 316 times.
✓ Branch 4 taken 2316 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 316 times.
4320 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8190
8191
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4320 times.
✓ Branch 2 taken 4320 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4320 times.
4320 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8192 4320 int32_t temp_vol = midi_volume;
8193
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 304 times.
4320 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8194 304 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8195 4320 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8196 4320 }
8197
8198 // array of voices, one for each sfx sample in the data file
8199 // 0+ = voice #
8200 // -1 = voice not allocated
8201 304 void Z_init_sound()
8202 {
8203
2/2
✓ Branch 0 taken 77824 times.
✓ Branch 1 taken 304 times.
78128 for(int32_t i=0; i<WAV_COUNT; i++)
8204 77824 sfx_voice[i]=-1;
8205
8206 304 const char* midis[ZC_MIDI_COUNT] = {
8207 "assets/dungeon.mid",
8208 "assets/ending.mid",
8209 "assets/gameover.mid",
8210 "assets/level9.mid",
8211 "assets/overworld.mid",
8212 "assets/title.mid",
8213 "assets/triforce.mid",
8214 };
8215
2/2
✓ Branch 0 taken 2128 times.
✓ Branch 1 taken 304 times.
2432 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8216 {
8217 2128 tunes[i].data = load_midi(midis[i]);
8218
1/2
✓ Branch 0 taken 2128 times.
✗ Branch 1 not taken.
2128 if (!tunes[i].data)
8219 Z_error_fatal("Missing required file %s\n", midis[i]);
8220 2128 }
8221
8222
2/2
✓ Branch 0 taken 76608 times.
✓ Branch 1 taken 304 times.
76912 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8223 76608 tunes[ZC_MIDI_COUNT+j].data=NULL;
8224
8225 304 master_volume(digi_volume,midi_volume);
8226 304 }
8227
8228 // returns number of voices currently allocated
8229 int32_t sfx_count()
8230 {
8231 int32_t c=0;
8232
8233 for(int32_t i=0; i<WAV_COUNT; i++)
8234 if(sfx_voice[i]!=-1)
8235 ++c;
8236
8237 return c;
8238 }
8239
8240 // clean up finished samples
8241 18287743 void sfx_cleanup()
8242 {
8243
2/2
✓ Branch 0 taken 4681662208 times.
✓ Branch 1 taken 18287743 times.
4699949951 for(int32_t i=0; i<WAV_COUNT; i++)
8244
3/4
✓ Branch 0 taken 1266119 times.
✓ Branch 1 taken 4680396089 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1266119 times.
4682928327 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8245 {
8246 1266119 deallocate_voice(sfx_voice[i]);
8247 1266119 sfx_voice[i]=-1;
8248 1266119 }
8249 18287743 }
8250
8251 1266284 SAMPLE* sfx_get_sample(int32_t index)
8252 {
8253 // check index
8254
2/4
✓ Branch 0 taken 1266284 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1266284 times.
1266284 if (index<=0 || index>=WAV_COUNT)
8255 return nullptr;
8256
8257
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 820037 times.
1266284 if (sfxdat)
8258 {
8259
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8260 {
8261 446247 return (SAMPLE*)sfxdata[index].dat;
8262 }
8263 else
8264 {
8265 return (SAMPLE*)sfxdata[Z35].dat;
8266 }
8267 }
8268 else
8269 {
8270 820037 return &customsfxdata[index];
8271 }
8272
8273 return nullptr;
8274 1266284 }
8275
8276 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8277 // if a voice is already allocated (and/or playing), then it just returns true
8278 // Returns true: voice is allocated
8279 // false: unsuccessful
8280 1864270 bool sfx_init(int32_t index)
8281 {
8282 // check index
8283
3/4
✓ Branch 0 taken 1398705 times.
✓ Branch 1 taken 465565 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1398705 times.
1864270 if(index<=0 || index>=WAV_COUNT)
8284 465565 return false;
8285
8286
2/2
✓ Branch 0 taken 132481 times.
✓ Branch 1 taken 1266224 times.
1398705 if (sfx_voice[index] == -1)
8287 {
8288 1266224 SAMPLE* sample = sfx_get_sample(index);
8289
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1266224 times.
1266224 if (!sample)
8290 return false;
8291
8292 1266224 sfx_voice[index] = allocate_voice(sample);
8293 1266224 }
8294
8295 1398705 return sfx_voice[index] != -1;
8296 1864270 }
8297
8298 int32_t sfx_get_default_freq(int32_t index)
8299 {
8300 if (sfxdat)
8301 {
8302 if (index < Z35)
8303 {
8304 return ((SAMPLE*)sfxdata[index].dat)->freq;
8305 }
8306 else
8307 {
8308 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8309 }
8310 }
8311 else
8312 {
8313 return customsfxdata[index].freq;
8314 }
8315 }
8316
8317 int32_t sfx_get_length(int32_t index)
8318 {
8319 if (sfxdat)
8320 {
8321 if (index < Z35)
8322 {
8323 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8324 }
8325 else
8326 {
8327 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8328 }
8329 }
8330 else
8331 {
8332 return int32_t(customsfxdata[index].len);
8333 }
8334 }
8335
8336 // plays an sfx sample
8337 1864270 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8338 {
8339
2/2
✓ Branch 0 taken 1398705 times.
✓ Branch 1 taken 465565 times.
1864270 if(!sfx_init(index))
8340 465565 return;
8341
1/2
✓ Branch 0 taken 1398705 times.
✗ Branch 1 not taken.
1398705 if (!is_headless())
8342 {
8343 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8344 voice_set_pan(sfx_voice[index], pan);
8345
8346 // Only used by ZScript currently
8347 if (freq <= -1)
8348 {
8349 freq = sfx_get_default_freq(index);
8350 }
8351 voice_set_frequency(sfx_voice[index], freq);
8352
8353 // Only used by ZScript currently
8354 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8355 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8356 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8357 voice_set_volume(sfx_voice[index], temp_volume);
8358
8359 int32_t pos = voice_get_position(sfx_voice[index]);
8360
8361 if (restart) voice_set_position(sfx_voice[index], 0);
8362
8363 if (pos <= 0)
8364 voice_start(sfx_voice[index]);
8365 }
8366
8367
4/4
✓ Branch 0 taken 864392 times.
✓ Branch 1 taken 534313 times.
✓ Branch 2 taken 8 times.
✓ Branch 3 taken 864384 times.
1398705 if (restart && replay_is_debug())
8368 {
8369 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8370 864384 const char* sfx_name = sfx_string[index];
8371
2/2
✓ Branch 0 taken 852585 times.
✓ Branch 1 taken 11799 times.
864384 if (strcmp(sfx_name, "Hero is hit") == 0)
8372 11799 sfx_name = "Player is hit";
8373
2/2
✓ Branch 0 taken 852458 times.
✓ Branch 1 taken 127 times.
852585 else if (strcmp(sfx_name, "Hero dies") == 0)
8374 127 sfx_name = "Player dies";
8375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 864384 times.
864384 replay_step_comment(fmt::format("sfx {}", sfx_name));
8376 864384 }
8377 1864270 }
8378
8379 // true if sfx is allocated
8380 203255 bool sfx_allocated(int32_t index)
8381 {
8382
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8383 }
8384
8385 // start it (in loop mode) if it's not already playing,
8386 // otherwise adjust it to play in loop mode -DD
8387 118448 void cont_sfx(int32_t index)
8388 {
8389
1/2
✓ Branch 0 taken 118448 times.
✗ Branch 1 not taken.
118448 if (is_headless())
8390 118448 return;
8391
8392 if(!sfx_init(index))
8393 {
8394 return;
8395 }
8396
8397 if(voice_get_position(sfx_voice[index])<=0)
8398 {
8399 voice_set_position(sfx_voice[index],0);
8400 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8401 voice_set_volume(sfx_voice[index], sfx_volume);
8402 voice_start(sfx_voice[index]);
8403 }
8404 else
8405 {
8406 adjust_sfx(index, 128, true);
8407 }
8408 118448 }
8409
8410 // adjust parameters while playing
8411 5339 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8412 {
8413
4/6
✓ Branch 0 taken 4506 times.
✓ Branch 1 taken 833 times.
✓ Branch 2 taken 4506 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4506 times.
5339 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8414 5339 return;
8415
8416 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8417 voice_set_pan(sfx_voice[index],pan);
8418 5339 }
8419
8420 // pauses a voice
8421 3248 void pause_sfx(int32_t index)
8422 {
8423
3/6
✓ Branch 0 taken 3248 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3248 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3248 times.
3248 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8424 voice_stop(sfx_voice[index]);
8425 3248 }
8426
8427 // resumes a voice
8428 1368 void resume_sfx(int32_t index)
8429 {
8430
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1368 times.
1368 if (is_headless())
8431 1368 return;
8432
8433 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8434 voice_start(sfx_voice[index]);
8435 1368 }
8436
8437 // pauses all active voices
8438 1072 void pause_all_sfx()
8439 {
8440
2/2
✓ Branch 0 taken 274432 times.
✓ Branch 1 taken 1072 times.
275504 for(int32_t i=0; i<WAV_COUNT; i++)
8441
2/2
✓ Branch 0 taken 274430 times.
✓ Branch 1 taken 2 times.
274434 if(sfx_voice[i]!=-1)
8442 2 voice_stop(sfx_voice[i]);
8443 1072 }
8444
8445 // resumes all paused voices
8446 1017 void resume_all_sfx()
8447 {
8448
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8449
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8450 voice_start(sfx_voice[i]);
8451 1017 }
8452
8453 // stops an sfx and deallocates the voice
8454 14597370 void stop_sfx(int32_t index)
8455 {
8456
3/4
✓ Branch 0 taken 14350396 times.
✓ Branch 1 taken 246974 times.
✓ Branch 2 taken 14350396 times.
✗ Branch 3 not taken.
14597370 if(index<=0 || index>=WAV_COUNT)
8457 246974 return;
8458
8459
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14350349 times.
14350396 if(sfx_voice[index]!=-1)
8460 {
8461 47 deallocate_voice(sfx_voice[index]);
8462 47 sfx_voice[index]=-1;
8463 47 }
8464 14597370 }
8465
8466 // Stops SFX played by Hero's item of the given family
8467 162791 void stop_item_sfx(int32_t family)
8468 {
8469 162791 int32_t id=current_item_id(family);
8470
8471
2/2
✓ Branch 0 taken 161689 times.
✓ Branch 1 taken 1102 times.
162791 if(id<0)
8472 161689 return;
8473
8474 1102 stop_sfx(itemsbuf[id].usesound);
8475 162791 }
8476
8477 9343 void kill_sfx()
8478 {
8479
2/2
✓ Branch 0 taken 2391808 times.
✓ Branch 1 taken 9343 times.
2401151 for(int32_t i=0; i<WAV_COUNT; i++)
8480
2/2
✓ Branch 0 taken 2391750 times.
✓ Branch 1 taken 58 times.
2391866 if(sfx_voice[i]!=-1)
8481 {
8482 58 deallocate_voice(sfx_voice[i]);
8483 58 sfx_voice[i]=-1;
8484 58 }
8485 9343 }
8486
8487 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8488 1181706 int32_t pan(int32_t x)
8489 {
8490
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1181706 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1181706 switch(pan_style)
8491 {
8492 // MONO
8493 case 0:
8494 return 128;
8495
8496 // 1/2
8497 case 1:
8498 1181706 x -= viewport.x;
8499 1181706 return vbound((x>>1)+68,0,255);
8500
8501 // 3/4
8502 case 2:
8503 x -= viewport.x;
8504 return vbound(((x*3)>>2)+36,0,255);
8505
8506 // FULL
8507 case 3:
8508 default:
8509 x -= viewport.x;
8510 return vbound(x,0,255);
8511 }
8512 1181706 }
8513
8514 50344583 bool joybtn(int32_t b)
8515 {
8516
1/2
✓ Branch 0 taken 50344583 times.
✗ Branch 1 not taken.
50344583 if(b == 0)
8517 return false;
8518
1/2
✓ Branch 0 taken 50344583 times.
✗ Branch 1 not taken.
50344583 if (b-1 >= joy[joystick_index].num_buttons)
8519 50344583 return false;
8520
8521 return joy[joystick_index].button[b-1].b !=0;
8522 50344583 }
8523
8524 bool joystick(int32_t s)
8525 {
8526 if(s < 0)
8527 return false;
8528 if (s >= joy[joystick_index].num_sticks)
8529 return false;
8530
8531 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8532 {
8533 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8534 return true;
8535 }
8536 return false;
8537 }
8538
8539 const char* joybtn_name(int32_t b)
8540 {
8541 if (b <= 0 || b > joy[joystick_index].num_buttons)
8542 return "";
8543
8544 return joy[joystick_index].button[b-1].name;
8545 }
8546
8547 const char* joystick_name(int32_t s)
8548 {
8549 if (s < 0 || s >= joy[joystick_index].num_sticks)
8550 return "";
8551
8552 return joy[joystick_index].stick[s].name;
8553 }
8554
8555 int32_t button_pressed()
8556 {
8557 if (joystick_index >= MAX_JOYSTICKS)
8558 return 0;
8559
8560 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8561 {
8562 if(joybtn(i))
8563 return i;
8564 }
8565
8566 return 0;
8567 }
8568
8569 int32_t next_press_key();
8570
8571 int32_t next_joy_input(bool buttons)
8572 {
8573 clear_keybuf();
8574
8575 //first, we need to wait until they're pressing no buttons
8576 for(;;)
8577 {
8578 if(keypressed())
8579 {
8580 switch(readkey()>>8)
8581 {
8582 case KEY_ESC:
8583 return -1;
8584
8585 case KEY_SPACE:
8586 return 0;
8587 }
8588 }
8589
8590 poll_joystick();
8591 bool done = true;
8592
8593 if (buttons)
8594 {
8595 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8596 {
8597 if(joybtn(i)) done = false;
8598 }
8599 }
8600 else
8601 {
8602 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8603 {
8604 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8605 return -2;
8606 }
8607 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8608 {
8609 if(joystick(i)) done = false;
8610 }
8611 }
8612
8613 if(done) break;
8614 rest(1);
8615 }
8616
8617 //now, we need to wait for them to press any button
8618 for(;;)
8619 {
8620 if(keypressed())
8621 {
8622 switch(readkey()>>8)
8623 {
8624 case KEY_ESC:
8625 return -1;
8626
8627 case KEY_SPACE:
8628 return 0;
8629 }
8630 }
8631
8632 poll_joystick();
8633
8634 if (buttons)
8635 {
8636 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8637 {
8638 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8639 return -2;
8640 }
8641 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8642 {
8643 if(joybtn(i))
8644 return i;
8645 }
8646 }
8647 else
8648 {
8649 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8650 {
8651 if(joystick(i))
8652 return i;
8653 }
8654 }
8655 rest(1);
8656 }
8657 }
8658
8659 7762171 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8660 {
8661
2/2
✓ Branch 0 taken 7733904 times.
✓ Branch 1 taken 28267 times.
7762171 bool ret = btn && !flag;
8662 7762171 flag = rawbtn;
8663
8664 7762171 return ret;
8665 }
8666 376485467 static bool rButton(bool &btn, bool &flag)
8667 {
8668
2/2
✓ Branch 0 taken 362594942 times.
✓ Branch 1 taken 13890525 times.
376485467 bool ret = btn && !flag;
8669 376485467 flag = btn;
8670
8671 376485467 return ret;
8672 }
8673 4635304 static bool rButtonPeek(bool btn, bool flag)
8674 {
8675
2/2
✓ Branch 0 taken 4292961 times.
✓ Branch 1 taken 342343 times.
4635304 if(!btn)
8676 {
8677 4292961 return false;
8678 }
8679
2/2
✓ Branch 0 taken 33477 times.
✓ Branch 1 taken 308866 times.
342343 else if(!flag)
8680 {
8681 33477 return true;
8682 }
8683
8684 308866 return false;
8685 4635304 }
8686
8687 // Updated only by keyboard/gamepad.
8688 // If in replay mode, this is set directly by the replay system.
8689 // This should never be read from directly - use control_state instead.
8690 bool raw_control_state[ZC_CONTROL_STATES];
8691
8692 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8693 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8694 // lasts until the next call to load_control_state.
8695 bool control_state[ZC_CONTROL_STATES];
8696 bool disable_control[ZC_CONTROL_STATES];
8697 bool drunk_toggle_state[11];
8698 bool disabledKeys[127];
8699 bool KeyInput[127];
8700 bool KeyPress[127];
8701
8702 bool key_current_frame[127];
8703 bool key_previous_frame[127];
8704
8705 static bool key_system[127];
8706 static bool key_system_previous[127];
8707 static bool key_system_press[127];
8708
8709 bool button_press[ZC_CONTROL_STATES];
8710 bool button_hold[ZC_CONTROL_STATES];
8711
8712 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8713 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8714 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8715 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8716 #define STICK_PRECISION 56 //define your own sensitivity
8717
8718 15643234 void load_control_state()
8719 {
8720 15643234 load_control_called_this_frame = true;
8721
8722
2/2
✓ Branch 0 taken 12440172 times.
✓ Branch 1 taken 3203062 times.
15643234 if (replay_version_check(8, 11))
8723 {
8724
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8725 57655116 down_control_states[i] = raw_control_state[i];
8726 3203062 }
8727
8728
2/2
✓ Branch 0 taken 15643213 times.
✓ Branch 1 taken 21 times.
15643234 if (!replay_is_replaying())
8729 {
8730
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8731
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8732
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8733
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8734
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8735
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8736
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8737
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8738
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8744
8745
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8746 {
8747 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8748 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8749 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8750 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8751 }
8752 else
8753 {
8754 21 raw_control_state[14] = false;
8755 21 raw_control_state[15] = false;
8756 21 raw_control_state[16] = false;
8757 21 raw_control_state[17] = false;
8758 }
8759 21 }
8760
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15643229 times.
15643234 if (replay_is_active())
8761 {
8762
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14431529 times.
15643229 if (replay_get_version() < 3)
8763 1211700 replay_poll();
8764
4/4
✓ Branch 0 taken 14431508 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12670133 times.
✓ Branch 3 taken 1761375 times.
14431529 else if (replay_is_replaying() && replay_get_version() < 6)
8765 1761375 replay_peek_input();
8766
4/4
✓ Branch 0 taken 12670133 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9467071 times.
✓ Branch 3 taken 3203062 times.
12670154 else if (replay_is_replaying() && replay_version_check(8, 11))
8767 3203062 replay_peek_input();
8768
2/2
✓ Branch 0 taken 14303287 times.
✓ Branch 1 taken 1339942 times.
15643229 if (replay_get_version() == 8)
8769 1339942 update_keys();
8770 15643229 }
8771
8772 // Some test replay files were made before a serious input bug was fixed, so instead
8773 // of re-doing them or tossing them out, just check for that zplay version.
8774
3/4
✓ Branch 0 taken 15643224 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15521324 times.
15643234 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8775
2/2
✓ Branch 0 taken 281578032 times.
✓ Branch 1 taken 15643224 times.
297221256 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8776 {
8777 281578032 control_state[i] = raw_control_state[i];
8778
4/4
✓ Branch 0 taken 53024022 times.
✓ Branch 1 taken 228554010 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412028 times.
281578032 if (botched_input && !control_state[i])
8779 50412028 down_control_states[i] = false;
8780 281578032 }
8781 15643224 bool did_bad_cutscene_btn = false;
8782
2/2
✓ Branch 0 taken 15643224 times.
✓ Branch 1 taken 281578032 times.
297221256 for(int q = 0; q < 18; ++q)
8783
4/4
✓ Branch 0 taken 13319988 times.
✓ Branch 1 taken 268258044 times.
✓ Branch 2 taken 13318405 times.
✓ Branch 3 taken 1583 times.
281579615 if(control_state[q] && !active_cutscene.can_button(q))
8784 {
8785 1583 control_state[q] = false;
8786 1583 did_bad_cutscene_btn = true;
8787 1583 }
8788
2/2
✓ Branch 0 taken 15642079 times.
✓ Branch 1 taken 1145 times.
15643224 if(did_bad_cutscene_btn)
8789 1145 active_cutscene.error();
8790
8791 15643224 button_press[0]=rButton(control_state[0],button_hold[0]);
8792 15643224 button_press[1]=rButton(control_state[1],button_hold[1]);
8793 15643224 button_press[2]=rButton(control_state[2],button_hold[2]);
8794 15643224 button_press[3]=rButton(control_state[3],button_hold[3]);
8795 15643224 button_press[4]=rButton(control_state[4],button_hold[4]);
8796 15643224 button_press[5]=rButton(control_state[5],button_hold[5]);
8797 15643224 button_press[6]=rButton(control_state[6],button_hold[6]);
8798 15643224 button_press[7]=rButton(control_state[7],button_hold[7]);
8799 15643224 button_press[8]=rButton(control_state[8],button_hold[8]);
8800 15643224 button_press[9]=rButton(control_state[9],button_hold[9]);
8801 15643224 button_press[10]=rButton(control_state[10],button_hold[10]);
8802 15643224 button_press[11]=rButton(control_state[11],button_hold[11]);
8803 15643224 button_press[12]=rButton(control_state[12],button_hold[12]);
8804 15643224 button_press[13]=rButton(control_state[13],button_hold[13]);
8805 15643224 button_press[14]=rButton(control_state[14],button_hold[14]);
8806 15643224 button_press[15]=rButton(control_state[15],button_hold[15]);
8807 15643224 button_press[16]=rButton(control_state[16],button_hold[16]);
8808 15643224 button_press[17]=rButton(control_state[17],button_hold[17]);
8809 15643224 }
8810
8811 // Returns true if any game key is pressed. This is needed because keypressed()
8812 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8813 78672357 bool zc_key_pressed()
8814 //may also need to use zc_getrawkey
8815 {
8816
7/10
✓ Branch 0 taken 63538750 times.
✓ Branch 1 taken 15133607 times.
✓ Branch 2 taken 15133607 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15133607 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12400717 times.
✓ Branch 7 taken 12400717 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4953791 times.
83626148 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8817
4/6
✓ Branch 0 taken 12400717 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12400717 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9440395 times.
✓ Branch 5 taken 9440395 times.
12400717 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8818
4/6
✓ Branch 0 taken 9440395 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9440395 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6246749 times.
✓ Branch 5 taken 6246749 times.
9440395 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8819
4/6
✓ Branch 0 taken 6246749 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6246749 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5362886 times.
✓ Branch 5 taken 5362886 times.
6246749 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8820
1/2
✓ Branch 0 taken 5362886 times.
✗ Branch 1 not taken.
5362886 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8821
3/4
✓ Branch 0 taken 5175686 times.
✓ Branch 1 taken 187200 times.
✓ Branch 2 taken 5175686 times.
✗ Branch 3 not taken.
5362886 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8822
3/4
✓ Branch 0 taken 5028763 times.
✓ Branch 1 taken 146923 times.
✓ Branch 2 taken 5028763 times.
✗ Branch 3 not taken.
5175686 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8823
3/4
✓ Branch 0 taken 5006607 times.
✓ Branch 1 taken 22156 times.
✓ Branch 2 taken 5006607 times.
✗ Branch 3 not taken.
5028763 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8824
3/4
✓ Branch 0 taken 4980238 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4980238 times.
✗ Branch 3 not taken.
5006607 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8825
3/4
✓ Branch 0 taken 4972953 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4972953 times.
✗ Branch 3 not taken.
4980238 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8826
3/4
✓ Branch 0 taken 4955714 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4955714 times.
✗ Branch 3 not taken.
4972953 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8827
3/4
✓ Branch 0 taken 4953885 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4953885 times.
✗ Branch 3 not taken.
4955714 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8828
3/4
✓ Branch 0 taken 4953850 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4953850 times.
✗ Branch 3 not taken.
4953885 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8829
2/2
✓ Branch 0 taken 4953791 times.
✓ Branch 1 taken 59 times.
4953850 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8830 140620060 return true;
8831
8832 4953791 return false;
8833 18496351 }
8834
8835 297489909 bool getInput(int32_t btn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8836 {
8837 297489909 bool ret = false, drunkstate = false, rawret = false;;
8838 297489909 bool* flag = &down_control_states[btn];
8839
2/7
✓ Branch 0 taken 278974648 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18515261 times.
297489909 switch(btn)
8840 {
8841 case btnF12:
8842 ret = zc_getkey(KEY_F12, ignoreDisable);
8843 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8844 eatEntirely = false;
8845 break;
8846 case btnF11:
8847 ret = zc_getkey(KEY_F11, ignoreDisable);
8848 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8849 eatEntirely = false;
8850 break;
8851 case btnF5:
8852 ret = zc_getkey(KEY_F5, ignoreDisable);
8853 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8854 eatEntirely = false;
8855 break;
8856 case btnQ:
8857 ret = zc_getkey(KEY_Q, ignoreDisable);
8858 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8859 eatEntirely = false;
8860 break;
8861 case btnI:
8862 ret = zc_getkey(KEY_I, ignoreDisable);
8863 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8864 eatEntirely = false;
8865 break;
8866 case btnM:
8867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18515261 times.
18515261 if(FFCore.kb_typing_mode) return false;
8868 18515261 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8869 18515261 eatEntirely = false;
8870 18515261 break;
8871 default: //control_state[] index
8872
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 278974648 times.
278974648 if(FFCore.kb_typing_mode) return false;
8873
6/6
✓ Branch 0 taken 277593314 times.
✓ Branch 1 taken 1381334 times.
✓ Branch 2 taken 17782611 times.
✓ Branch 3 taken 259810703 times.
✓ Branch 4 taken 17779638 times.
✓ Branch 5 taken 2973 times.
278974648 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8874
2/2
✓ Branch 0 taken 15907451 times.
✓ Branch 1 taken 263064224 times.
278971675 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8875
4/4
✓ Branch 0 taken 247866731 times.
✓ Branch 1 taken 31107917 times.
✓ Branch 2 taken 7186 times.
✓ Branch 3 taken 31100731 times.
310082565 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8876 278974648 rawret = raw_control_state[btn];
8877 278974648 }
8878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 297489909 times.
297489909 assert(flag);
8879
2/2
✓ Branch 0 taken 190184999 times.
✓ Branch 1 taken 107304910 times.
297489909 if(press)
8880 {
8881
2/2
✓ Branch 0 taken 4635304 times.
✓ Branch 1 taken 102669606 times.
107304910 if(peek)
8882 4635304 ret = rButtonPeek(ret, *flag);
8883
2/2
✓ Branch 0 taken 94907435 times.
✓ Branch 1 taken 7762171 times.
102669606 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8884 7762171 else ret = rButton(ret, *flag, rawret);
8885 107304910 }
8886
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 297489909 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
297489909 if(eatEntirely && ret) control_state[btn] = false;
8887
4/4
✓ Branch 0 taken 222131112 times.
✓ Branch 1 taken 75358797 times.
✓ Branch 2 taken 222131031 times.
✓ Branch 3 taken 81 times.
297489909 if(drunk && drunkstate) ret = !ret;
8888 297489909 return ret;
8889 297489909 }
8890
8891 15021514 byte getIntBtnInput(byte intbtn, bool press, bool drunk, bool ignoreDisable, bool eatEntirely, bool peek)
8892 {
8893 15021514 byte ret = 0;
8894
2/2
✓ Branch 0 taken 10609139 times.
✓ Branch 1 taken 4412375 times.
15021514 if(intbtn & INT_BTN_A) ret |= getInput(btnA, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_A : 0;
8895
2/2
✓ Branch 0 taken 14812860 times.
✓ Branch 1 taken 208654 times.
15021514 if(intbtn & INT_BTN_B) ret |= getInput(btnB, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_B : 0;
8896
2/2
✓ Branch 0 taken 14814178 times.
✓ Branch 1 taken 207336 times.
15021514 if(intbtn & INT_BTN_L) ret |= getInput(btnL, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_L : 0;
8897
2/2
✓ Branch 0 taken 14814178 times.
✓ Branch 1 taken 207336 times.
15021514 if(intbtn & INT_BTN_R) ret |= getInput(btnR, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_R : 0;
8898
2/2
✓ Branch 0 taken 14814178 times.
✓ Branch 1 taken 207336 times.
15021514 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX1 : 0;
8899
2/2
✓ Branch 0 taken 14814178 times.
✓ Branch 1 taken 207336 times.
15021514 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX2 : 0;
8900
2/2
✓ Branch 0 taken 14814178 times.
✓ Branch 1 taken 207336 times.
15021514 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX3 : 0;
8901
2/2
✓ Branch 0 taken 14814063 times.
✓ Branch 1 taken 207451 times.
15021514 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, press, drunk, ignoreDisable, eatEntirely, peek) ? INT_BTN_EX4 : 0;
8902 15021514 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8903 }
8904
8905 7362 byte checkIntBtnVal(byte intbtn, byte vals)
8906 {
8907 7362 return intbtn&vals;
8908 }
8909
8910 3764668 bool Up()
8911 {
8912 3764668 return getInput(btnUp);
8913 }
8914 739226 bool Down()
8915 {
8916 739226 return getInput(btnDown);
8917 }
8918 1006614 bool Left()
8919 {
8920 1006614 return getInput(btnLeft);
8921 }
8922 1074253 bool Right()
8923 {
8924 1074253 return getInput(btnRight);
8925 }
8926 530032 bool cAbtn()
8927 {
8928 530032 return getInput(btnA);
8929 }
8930 3306234 bool cBbtn()
8931 {
8932 3306234 return getInput(btnB);
8933 }
8934 bool cSbtn()
8935 {
8936 return getInput(btnS);
8937 }
8938 208608 bool cLbtn()
8939 {
8940 208608 return getInput(btnL);
8941 }
8942 208608 bool cRbtn()
8943 {
8944 208608 return getInput(btnR);
8945 }
8946 bool cPbtn()
8947 {
8948 return getInput(btnP);
8949 }
8950 bool cEx1btn()
8951 {
8952 return getInput(btnEx1);
8953 }
8954 bool cEx2btn()
8955 {
8956 return getInput(btnEx2);
8957 }
8958 bool cEx3btn()
8959 {
8960 return getInput(btnEx3);
8961 }
8962 bool cEx4btn()
8963 {
8964 return getInput(btnEx4);
8965 }
8966 bool AxisUp()
8967 {
8968 return getInput(btnAxisUp);
8969 }
8970 bool AxisDown()
8971 {
8972 return getInput(btnAxisDown);
8973 }
8974 bool AxisLeft()
8975 {
8976 return getInput(btnAxisLeft);
8977 }
8978 bool AxisRight()
8979 {
8980 return getInput(btnAxisRight);
8981 }
8982
8983 bool cMbtn()
8984 {
8985 return getInput(btnM);
8986 }
8987 bool cF12()
8988 {
8989 return getInput(btnF12);
8990 }
8991 bool cF11()
8992 {
8993 return getInput(btnF11);
8994 }
8995 bool cF5()
8996 {
8997 return getInput(btnF5);
8998 }
8999 bool cQ()
9000 {
9001 return getInput(btnQ);
9002 }
9003 bool cI()
9004 {
9005 return getInput(btnI);
9006 }
9007
9008 211000 bool rUp()
9009 {
9010 211000 return getInput(btnUp, true);
9011 }
9012 210787 bool rDown()
9013 {
9014 210787 return getInput(btnDown, true);
9015 }
9016 210591 bool rLeft()
9017 {
9018 210591 return getInput(btnLeft, true);
9019 }
9020 209851 bool rRight()
9021 {
9022 209851 return getInput(btnRight, true);
9023 }
9024 7054 bool rAbtn()
9025 {
9026 7054 return getInput(btnA, true);
9027 }
9028 2406 bool rBbtn()
9029 {
9030 2406 return getInput(btnB, true);
9031 }
9032 14496504 bool rSbtn()
9033 {
9034 14496504 return getInput(btnS, true);
9035 }
9036 18496351 bool rMbtn()
9037 {
9038 18496351 return getInput(btnM, true);
9039 }
9040 185734 bool rLbtn()
9041 {
9042 185734 return getInput(btnL, true);
9043 }
9044 185729 bool rRbtn()
9045 {
9046 185729 return getInput(btnR, true);
9047 }
9048 14496693 bool rPbtn()
9049 {
9050 14496693 return getInput(btnP, true);
9051 }
9052 bool rEx1btn()
9053 {
9054 return getInput(btnEx1, true);
9055 }
9056 bool rEx2btn()
9057 {
9058 return getInput(btnEx2, true);
9059 }
9060 196380 bool rEx3btn()
9061 {
9062 196380 return getInput(btnEx3, true);
9063 }
9064 196380 bool rEx4btn()
9065 {
9066 196380 return getInput(btnEx4, true);
9067 }
9068 bool rAxisUp()
9069 {
9070 return getInput(btnAxisUp, true);
9071 }
9072 bool rAxisDown()
9073 {
9074 return getInput(btnAxisDown, true);
9075 }
9076 bool rAxisLeft()
9077 {
9078 return getInput(btnAxisLeft, true);
9079 }
9080 bool rAxisRight()
9081 {
9082 return getInput(btnAxisRight, true);
9083 }
9084
9085 bool rF11()
9086 {
9087 return getInput(btnF11, true);
9088 }
9089 bool rQ()
9090 {
9091 return getInput(btnQ, true);
9092 }
9093 bool rI()
9094 {
9095 return getInput(btnI, true);
9096 }
9097
9098 36945680 bool DrunkUp()
9099 {
9100 36945680 return getInput(btnUp, false, true);
9101 }
9102 33722352 bool DrunkDown()
9103 {
9104 33722352 return getInput(btnDown, false, true);
9105 }
9106 19730003 bool DrunkLeft()
9107 {
9108 19730003 return getInput(btnLeft, false, true);
9109 }
9110 16768253 bool DrunkRight()
9111 {
9112 16768253 return getInput(btnRight, false, true);
9113 }
9114 15908055 bool DrunkcAbtn()
9115 {
9116 15908055 return getInput(btnA, false, true);
9117 }
9118 15340739 bool DrunkcBbtn()
9119 {
9120 15340739 return getInput(btnB, false, true);
9121 }
9122 14287892 bool DrunkcEx1btn()
9123 {
9124 14287892 return getInput(btnEx1, false, true);
9125 }
9126 14286524 bool DrunkcEx2btn()
9127 {
9128 14286524 return getInput(btnEx2, false, true);
9129 }
9130 bool DrunkcSbtn()
9131 {
9132 return getInput(btnS, false, true);
9133 }
9134 bool DrunkcMbtn()
9135 {
9136 return getInput(btnM, false, true);
9137 }
9138 bool DrunkcLbtn()
9139 {
9140 return getInput(btnL, false, true);
9141 }
9142 bool DrunkcRbtn()
9143 {
9144 return getInput(btnR, false, true);
9145 }
9146 bool DrunkcPbtn()
9147 {
9148 return getInput(btnP, false, true);
9149 }
9150
9151 bool DrunkrUp()
9152 {
9153 return getInput(btnUp, true, true);
9154 }
9155 bool DrunkrDown()
9156 {
9157 return getInput(btnDown, true, true);
9158 }
9159 bool DrunkrLeft()
9160 {
9161 return getInput(btnLeft, true, true);
9162 }
9163 bool DrunkrRight()
9164 {
9165 return getInput(btnRight, true, true);
9166 }
9167 11947924 bool DrunkrAbtn()
9168 {
9169 11947924 return getInput(btnA, true, true);
9170 }
9171 11976576 bool DrunkrBbtn()
9172 {
9173 11976576 return getInput(btnB, true, true);
9174 }
9175 549513 bool DrunkrEx1btn()
9176 {
9177 549513 return getInput(btnEx1, true, true);
9178 }
9179 549314 bool DrunkrEx2btn()
9180 {
9181 549314 return getInput(btnEx2, true, true);
9182 }
9183 bool DrunkrEx3btn()
9184 {
9185 return getInput(btnEx3, true, true);
9186 }
9187 bool DrunkrEx4btn()
9188 {
9189 return getInput(btnEx4, true, true);
9190 }
9191 bool DrunkrSbtn()
9192 {
9193 return getInput(btnS, true, true);
9194 }
9195 bool DrunkrMbtn()
9196 {
9197 return getInput(btnM, true, true);
9198 }
9199 12958012 bool DrunkrLbtn()
9200 {
9201 12958012 return getInput(btnL, true, true);
9202 }
9203 12952707 bool DrunkrRbtn()
9204 {
9205 12952707 return getInput(btnR, true, true);
9206 }
9207 bool DrunkrPbtn()
9208 {
9209 return getInput(btnP, true, true);
9210 }
9211
9212 18910 void eat_buttons()
9213 {
9214 18910 getInput(btnA, true, false, true);
9215 18910 getInput(btnB, true, false, true);
9216 18910 getInput(btnS, true, false, true);
9217 18910 getInput(btnM, true, false, true);
9218 18910 getInput(btnL, true, false, true);
9219 18910 getInput(btnR, true, false, true);
9220 18910 getInput(btnP, true, false, true);
9221 18910 getInput(btnEx1, true, false, true);
9222 18910 getInput(btnEx2, true, false, true);
9223 18910 getInput(btnEx3, true, false, true);
9224 18910 getInput(btnEx4, true, false, true);
9225 18910 }
9226
9227 // Is true for the _first frame_ of a key press.
9228 // But! it is possible that a script manually sets the value of KeyPress,
9229 // in which case it will be restored to the "true" value based on `key_current_frame`
9230 // and `key_previous_frame` on the next frame.
9231 55 bool zc_readkey(int32_t k, bool ignoreDisable)
9232 {
9233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 if(ignoreDisable) return KeyPress[k];
9234
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 55 times.
55 switch(k)
9235 {
9236 case KEY_F7:
9237 case KEY_F8:
9238 case KEY_F9:
9239 return KeyPress[k];
9240
9241 default:
9242
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 10 times.
55 return KeyPress[k] && !disabledKeys[k];
9243 }
9244 55 }
9245
9246 // Is true for _every frame_ a key is held down.
9247 // But! it is possible that a script manually sets the value of KeyInput,
9248 // in which case it will be restored to the "true" value based on `key_current_frame`
9249 // on the next frame.
9250 bool zc_getkey(int32_t k, bool ignoreDisable)
9251 {
9252 if(ignoreDisable) return KeyInput[k];
9253 switch(k)
9254 {
9255 case KEY_F7:
9256 case KEY_F8:
9257 case KEY_F9:
9258 return KeyInput[k];
9259
9260 default:
9261 return KeyInput[k] && !disabledKeys[k];
9262 }
9263 }
9264
9265 // Reads (and then clears) the current frame key state directly.
9266 // Scripts can also modify `key_current_frame`.
9267 927 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9268 {
9269
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 925 times.
927 if(zc_getrawkey(k, ignoreDisable))
9270 {
9271 2 _key[k]=key[k]=key_current_frame[k]=0;
9272 2 return true;
9273 }
9274 925 _key[k]=key[k]=key_current_frame[k]=0;
9275 925 return false;
9276 927 }
9277
9278 // Reads the current frame key state directly.
9279 // Scripts can also modify `key_current_frame`.
9280 125624883 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9281 {
9282
2/2
✓ Branch 0 taken 107128422 times.
✓ Branch 1 taken 18496461 times.
125624883 if(ignoreDisable) return key_current_frame[k];
9283
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496461 times.
18496461 switch(k)
9284 {
9285 case KEY_F7:
9286 case KEY_F8:
9287 case KEY_F9:
9288 return key_current_frame[k];
9289
9290 default:
9291
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18496461 times.
18496461 return key_current_frame[k] && !disabledKeys[k];
9292 }
9293 125624883 }
9294
9295 // Only used for a handful of keys, like tilde and Function keys.
9296 // This state is never read within the game.
9297 // It exists so that all keyboard input still functions during replay,
9298 // without inadvertently doing things like toggling throttling if the player
9299 // presses ~
9300 bool zc_get_system_key(int32_t k)
9301 {
9302 return key_system[k];
9303 }
9304
9305 // True for the _first_ frame of a key press.
9306 166467159 bool zc_read_system_key(int32_t k)
9307 {
9308 166467159 return key_system_press[k];
9309 }
9310
9311 2349036577 bool is_system_key(int32_t k)
9312 {
9313
2/2
✓ Branch 0 taken 2182569418 times.
✓ Branch 1 taken 166467159 times.
2349036577 switch (k)
9314 {
9315 case KEY_BACKQUOTE:
9316 case KEY_CLOSEBRACE:
9317 case KEY_END:
9318 case KEY_HOME:
9319 case KEY_OPENBRACE:
9320 case KEY_PGDN:
9321 case KEY_PGUP:
9322 case KEY_TAB:
9323 case KEY_TILDE:
9324 166467159 return true;
9325 }
9326 2182569418 return is_Fkey(k);
9327 2349036577 }
9328
9329 18496351 void update_system_keys()
9330 {
9331
2/2
✓ Branch 0 taken 2349036577 times.
✓ Branch 1 taken 18496351 times.
2367532928 for (int32_t q = 0; q < 127; ++q)
9332 {
9333
2/2
✓ Branch 0 taken 388423371 times.
✓ Branch 1 taken 1960613206 times.
2349036577 if (!is_system_key(q))
9334 1960613206 continue;
9335
9336 388423371 key_system[q] = key[q];
9337
1/2
✓ Branch 0 taken 388423371 times.
✗ Branch 1 not taken.
388423371 key_system_press[q] = key_system[q] && !key_system_previous[q];
9338 388423371 key_system_previous[q] = key_system[q];
9339 388423371 }
9340 18496351 }
9341
9342 19836293 void update_keys()
9343 {
9344
2/2
✓ Branch 0 taken 2519209211 times.
✓ Branch 1 taken 19836293 times.
2539045504 for (int32_t q = 0; q < 127; ++q)
9345 {
9346 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9347
2/2
✓ Branch 0 taken 2519196511 times.
✓ Branch 1 taken 12700 times.
2519209211 if (!replay_is_replaying())
9348 12700 key_current_frame[q] = key[q];
9349
9350
2/2
✓ Branch 0 taken 2499846099 times.
✓ Branch 1 taken 19363112 times.
2519209211 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9351 2519209211 KeyInput[q] = key_current_frame[q];
9352 2519209211 key_previous_frame[q] = key_current_frame[q];
9353 2519209211 }
9354 19836293 }
9355
9356